I have Spring Boot web application. It exposes REST API on port 8080. It also exposes management port 8081 with Spring Boot Management endpoints (http://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-monitoring.html).
I do not have any custom Tomcat configuration to achieve that. I just have property management.port=8081
in my application.properties
file.
I have JavaMelody configured as described in
https://github.com/javamelody/javamelody/wiki/UserGuideAdvanced#spring-boot-app
(I have my custom JavaMelodyConfiguration
class, with org.springframework.boot.web.servlet.FilterRegistrationBean
that registers net.bull.javamelody.MonitoringFilter
).
@Bean
public FilterRegistrationBean javaMelody() {
final FilterRegistrationBean javaMelody = new FilterRegistrationBean();
javaMelody.setFilter(new MonitoringFilter());
javaMelody.setAsyncSupported(true);
javaMelody.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC);
javaMelody.addUrlPatterns("/*");
return javaMelody;
}
With this configuration, Javamelody is exposed on port 8080 (business port). I would like to move it to 8081(management port). How to change that?
I use Spring Boot 1.4.2.RELEASE, javamelody 1.62.0
You can use the ReportServlet through a MvcEndpoint. Something like this:
(I also posted this here: https://github.com/javamelody/javamelody/issues/601)
EmbeddedTomcatConfiguration.java
application.yml
Application.java
and my suggestion for limiting accessing javamelody from a specific port would be to extend the javamelody filter and just chain the request if it comes from a specific port otherwise send back a 404.
From the logs:
This approach BTW exposes other endpoints on these ports. To solve this and limiting javamelody filter (/monitoring) to a specific port, you would need to write a filter that verifies path (servlet and filter path) being requested from allowable ports keeping in mind that the ordering of these filters is important.
Based on this answer and partial source code that I had already available when I answered this question, I had published a blog post about this topic at http://tech.asimio.net/2016/12/15/Configuring-Tomcat-to-Listen-on-Multiple-ports-using-Spring-Boot.html