zoukankan      html  css  js  c++  java
  • Idea新建springboot工程,需要使用外部的配置文件

    需求:
    使用Idea新建springboot工程,需要使用外部的配置文件,

    整体的目录结构如下:

    Spring Boot启动会扫描以下位置的application.properties或者application.yml文件作为spring boot的默认配置文件
    -file:/config/
    -file:./
    -classpath:/config/
    -classpath:/
    -以上是按照优先级从高到低的顺序,所有位置的文件都会被加载,高优先级的配置内容会覆盖低优先级配置内容。
    -我们也可以通过配置spring.config.location来改变默认配置。

    按照流行的说法,应该是可以加载的。

    直接新建config文件夹,添加配置文件后好像不行。


    解决方案:
    通过如下配置解决了IDEA里的运行问题:
    1、设置working directory

    到src文件夹

    2、设置config文件夹resources:

    设置后可以启动成功:


    打包问题
    打包不需要特殊配置,需要如下插件:

    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
    <excludes>
    <exclude>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    </exclude>
    </excludes>
    </configuration>
    </plugin>

    打包操作如下:

    打包后生成jar, 添加config文件夹下的配置文件启动:java -jar demo.jar 后报错如下:

    报错信息: no subdirectories found for mandatory directory location ‘file:./config/*/’.
    没明白为啥这样。。。。。;

    尝试解决的方式
    在config文件夹下 建一个文件夹,名称随意
    java -jar 重启服务
    问题解决;

  • 相关阅读:
    PHP快速排序算法
    PHP选择排序算法
    php几个常用的概率算法(抽奖、广告首选)
    免费Git客户端:sourcetree详细介绍
    apidoc @apiGroup兼容中文
    PHP中的精确计算bcadd,bcsub,bcmul,bcdiv 及 扩展安装
    mysql-表分区
    mysql表优化
    MySQL执行计划extra中的using index 和 using where using index 的区别
    mysql-锁
  • 原文地址:https://www.cnblogs.com/liangblog/p/14874536.html
Copyright © 2011-2022 走看看