So I just playing around with Spring Boot 2.0.4 and I notice this today. Not sure that I missed something or not. Please help me to check.
Spring Application
@SpringBootApplication
@EnableScheduling
public class Application extends SpringBootServletInitializer {
application.properties (located in src/main/resources)
server.port=8088
start the project using Intellij
2018-08-17 12:11:05 INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port(s): 8088 (http) with context path ''
start the project using java command line:
java -jar sample.jar --spring.config.location=D:\config\ --spring.profiles.active=dev
The application is not using the configured port
2018-08-17 11:25:25 INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port(s): 8080 (http) with context path ''
It's look like Spring Boot 2.0 ignored the default properties file (note: this configuration only in applications.properties no where else, so it won't be overlapped by another configuration files)
You specify spring.config.location
to start the uber-jar and from Spring Boot 2, specifying this argument replaces the default locations used by Spring as stated in the documentation.
When custom config locations are configured by using
spring.config.location
, they replace the default locations. For example, ifspring.config.location
is configured with the valueclasspath:/custom-config/
,file:./custom-config/
, the search order becomes the following:
file:./custom-config/
classpath:custom-config/
So I think that you have to explicitly add the application.properties
in spring.config.location
:
--spring.config.location=D:\config\,classpath:\application.properties
Or as alternative use spring.config.additional-location
such as --spring.config.additional-location=D:\config\
instead of spring.config.location
that will add rather than replace locations as stated by the documentation :
Alternatively, when custom config locations are configured by using spring.config.additional-location, they are used in addition to the default locations.