eclipse下spring boot 没有加载 application.properties

本文解决SpringBoot项目中application.properties配置文件无法被正确加载的问题,提供了两种解决方案:一是调整配置文件的位置;二是修改Eclipse的配置排除设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

     最近在跟着springboot官网(https://projects.spring.io/spring-boot/#quick-start)系统学习springboot的特性;

    根据样例搭建了一个简单springboot工程,但是出现无法加载配置文件 application.properties的情况;

    例如:

    

 配置文件在src/main/resources下,是官网推荐的标准配置,其中修改了启动端口

 

server.port=8443

 

但是在启动后无法加载里面的配置,还是8080

 

 

  

 

第一种方案:

 

官网的描述是这样的,有4个位置扫描:

在当前目录及其/config,或类路径及其/config;

写道
SpringApplication loads properties from application.properties files in the following locations and adds them to the Spring Environment:

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

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值