---
title: "eclipse下spring boot 没有加载 application.properties"
author: "wade6"
date: "2018-04-09T00:09:24Z"
tags: []
categories: ["开源软件"]
slug: "eclipse-spring-boot-application-properties"
draft: false
lastmod: "2018-04-09T00:09:24Z"
id: 2416000
url: "https://wade6.iteye.com/blog/2416000"
---

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

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

    例如：

      
![](http://dl2.iteye.com/upload/attachment/0129/4681/624aceef-877e-3bfd-af16-1c75b2cab0ee.png)  
 配置文件在src/main/resources下，是官网推荐的标准配置，其中修改了启动端口

 

```
server.port=8443
```

 

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

 

 

  ![](http://dl2.iteye.com/upload/attachment/0129/4683/9ef53f08-d7fb-3ab2-8ade-5901380d8c6d.png)

 

第一种方案：

 

官网的描述是这样的，有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

 

那怎么知道哪里是当前目录，看启动的信息：

![](http://dl2.iteye.com/upload/attachment/0129/4685/e121c1c8-d437-3ca9-9179-e100a1d07e6f.png)  
 

如上，调整位置如下，启动后成功加载配置文件

![](http://dl2.iteye.com/upload/attachment/0129/4687/9b9eafbb-638e-3f48-89ec-1d3513e8a049.png)

 

第二种方案：

 

还有一种方案，网上找到的，配置文件位置不变，只是修改eclipse的配置，

 

具体位置在： Project Properties --&gt; Java Build Path --&gt; Source(tab) --&gt; Source folders on build path: \[Exclusion section]

删除对  application.properties的过滤

 

![](http://dl2.iteye.com/upload/attachment/0129/4689/c07292be-3597-3516-99c9-9e0a8449b507.png)  
 

 

\----------------------------------------------

参考：

https://blog.csdn.net/wtunique/article/details/77877449

http://dongmj.iteye.com/blog/2376726