Spring boot under eclipse does not load application.properties

     Recently, I followed the springboot official website (https://projects.spring.io/spring-boot/#quick-start) to learn the features of springboot;

    A simple springboot project is built according to the sample, but the configuration file application.properties cannot be loaded;

    E.g:

    

 The configuration file is under src/main/resources, which is the standard configuration recommended by the official website, in which the startup port is modified.

 

server.port=8443

 

But the configuration inside cannot be loaded after startup, still 8080

 

 

  

 

The first option:

 

The description on the official website is like this, there are 4 locations to scan:

in the current directory and its /config, or the classpath and its /config;

wrote
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).

 Source: https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-external-config-application-property-files

 

So how do you know where the current directory is, look at the startup information:


 

As above, the adjustment position is as follows, and the configuration file is successfully loaded after startup


 

Second option:

 

There is another solution, found on the Internet, the location of the configuration file remains unchanged, just modify the configuration of eclipse,

 

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

Remove the filter on application.properties

 


 

 

----------------------------------------------

refer to:

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

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

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326071813&siteId=291194637