最近在跟着springboot官网(https://projects.spring.io/spring-boot/#quick-start)系统学习springboot的特性;
根据样例搭建了一个简单springboot工程,但是出现无法加载配置文件 application.properties的情况;
例如:
配置文件在src/main/resources下,是官网推荐的标准配置,其中修改了启动端口
server.port=8443
但是在启动后无法加载里面的配置,还是8080
第一种方案:
官网的描述是这样的,有4个位置扫描:
在当前目录及其/config,或类路径及其/config;
1.A /config subdirectory of the current directory
2.The current directory
3.A classpath /config package
4.The classpath root
The list is ordered by precedence (properties defined in locations higher in the list override those defined in lower locations).
出处:https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-external-config-application-property-files
那怎么知道哪里是当前目录,看启动的信息:
如上,调整位置如下,启动后成功加载配置文件
第二种方案:
还有一种方案,网上找到的,配置文件位置不变,只是修改eclipse的配置,
具体位置在: Project Properties --> Java Build Path --> Source(tab) --> Source folders on build path: [Exclusion section]
删除对 application.properties的过滤
----------------------------------------------
参考:
https://blog.youkuaiyun.com/wtunique/article/details/77877449
http://dongmj.iteye.com/blog/2376726