I've got a Spring Boot project where the server port always gets set to 8080, regardless of the server.port property. All properties except server.port gets overridden correctly. Property configuration bean:
@Bean
public PropertySourcesPlaceholderConfigurer properties() {
final PropertySourcesPlaceholderConfigurer poc = new PropertySourcesPlaceholderConfigurer();
poc.setIgnoreResourceNotFound(true);
poc.setIgnoreUnresolvablePlaceholders(true);
final List<Resource> list = new ArrayList<Resource>();
// default (dev) properties
list.add(new ClassPathResource(PROPERTIES_FILE));
// override with -Dproperties.location=C:/path/to/properties/ where overriding application.properties resides
list.add(new FileSystemResource(System.getProperty(EXTERNAL_ARGUMENT_NAME)+PROPERTIES_FILE));
poc.setLocations(list.toArray(new Resource[]{}));
return poc;
}
This means my classpath application.properties is the default (dev properties), which get overridden by jvm argument -Dproperties.location=C:\application\config.
The server.port property is not defined in my classpath properties file, so it defaults to 8080 in dev environment. This is fine, but for test I would like to specify the port. My external properties file contains this property:
server.port=10070
Logs:
[2016-01-19 11:14:10:010 CET] INFO [restartedMain] support.PropertySourcesPlaceholderConfigurer: Loading properties file from class path resource [application.properties]
[2016-01-19 11:14:10:010 CET] INFO [restartedMain] support.PropertySourcesPlaceholderConfigurer: Loading properties file from file [C:\var\opt\application\config\application.properties]
[2016-01-19 11:14:11:011 CET] INFO [restartedMain] support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$418ca8e8] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
[2016-01-19 11:14:11:011 CET] INFO [restartedMain] tomcat.TomcatEmbeddedServletContainer: Tomcat initialized with port(s): 8080 (http)
[2016-01-19 11:14:11:011 CET] INFO [restartedMain] core.StandardService: Starting service Tomcat
If you are using spring actuator in your project, by default it points to 8080, and if you want to change it, then in application.properties mention management.port = 9001
You can also try overriding the port at runtime with -Dserver.port= or --server.port=. Use later when you are running as java -jar. Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With