question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve the client configuration for usage in war-file deployments

See original GitHub issue

Would 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:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
joshistecommented, Jul 23, 2017

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 and spring.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.

0reactions
membersoundcommented, Aug 2, 2017

Great improvement, works as expected!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Assembling a web services-enabled client WAR file into ... - IBM
Read about configuring the assembly tool in the Rational Application Developer documentation. Migrate WAR files created with the Assembly ...
Read more >
Configure Web application deployment - IntelliJ IDEA - JetBrains
Configuring an artifact to deploy involves: Specifying the artifact type, name, and output directory. Adding static Web content resources.
Read more >
How to Deploy a WAR File to Apache Tomcat (Windows)
Start the Tomcat server. In the address area of the browser, type http://localhost:8080/DemoWebsite/DateJSP.jsp and submit that address to the browser.
Read more >
A Sample Java Web Application - War file to Deploy and Test
This post is about the Java J2EE web application and explaining what is Web Application and why they are called as WAR files, ......
Read more >
What is WAR, How to deploy WAR file in Tomcat Server
What is WAR, How to deploy WAR file in Tomcat Serverhttps://www.youtube.com/watch?v=sGwCAB46Zv8JAVA JSP file upload ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found