Improve the client configuration for usage in war-file deployments
See original GitHub issueWould it be possible to change the DefaultApplicationFactory
to retrieve the contextPath from ServletContext.getContextPath()
instead of reading property .path(server.getContextPath())
from server.contextPath
?
Or even better: just inject @Value("#{servletContext.contextPath}") String servletContextPath
into the constructor.
Reason: when I deploy a *.war application to tomcat, I might create subcontext path like:
myapp#v1.war -> /webapps/myapp/v1
myapp#v2.war -> /webapps/myapp/v2
...
If always the server.contextPath
property is read, I have to change that property in application.properties
before redeployment.
But I would like to just rename the war file (eg myapp#v8.war), deploy and then spring-boot-admin should automatically register as a client using the …/v8 contextpath.
Currently the following is a workaround. It just overrides the contextpath dynamically retrieved from ServletContext.
@Configuration
public class AdminClientConfiguration extends SpringBootAdminClientAutoConfiguration {
@Bean
public ApplicationFactory applicationFactory(AdminClientProperties client,
ManagementServerProperties management, ServerProperties server,
@Value("${endpoints.health.path:/${endpoints.health.id:health}}") String healthEndpointPath,
@Value("#{servletContext.contextPath}") String servletContextPath) {
server.setContextPath(servletContextPath); //<- this is the change
return super.applicationFactory(client, management, server, healthEndpointPath);
}
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:5
Top GitHub Comments
With this commit two new properties were added to ease the client configuration when used in servlet containers:
spring.boot.admin.client.management-base-url
andspring.boot.admin.client.service-base-url
. Both properties can be used to specify protocol, host and port for the urls. The paths will still be guessed and appended to the base-urls. Additionally the servlet context path is not read from the properties but from the ServletContext itself.Great improvement, works as expected!