Monitoring spring beans with JavaMelody in the Spring-Boot project

I'm trying to control a REST application based on the Spring tutorial Creating a RESTful Web Service , but on the Java Melody documentation page, the configuration depends on web.xml, but the Spring project does not have such a file. I tried using java melody annotations and set contextConfigLocation to WebInitializer, but when I enter the Java Melody page, I don't see the Spring section.

I have my WebInitializar like this:

public class WebInitializer extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(Application.class).properties(); } @Override public void onStartup(ServletContext servletContext) throws ServletException { servletContext.setInitParameter("contextConfigLocation", "classpath:net/bull/javamelody/monitoring-spring.xml"); super.onStartup(servletContext); } } 

I set contextConfigLocation as Java Melody documentation.

And my controller:

 @RestController @MonitoredWithSpring public class GreetingController { private static final String template = "Hello, %s!"; private final AtomicLong counter = new AtomicLong(); @RequestMapping("/greeting") public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) { return new Greeting(counter.incrementAndGet(), String.format(template, name)); } } 

Any tips to make it work?

+7
spring spring-boot java-melody
source share
2 answers

In a web application, you only need javamelody jancy junction, and register two beans application contexts in spring:

 @Bean public HttpSessionListener javaMelodyListener(){ return new net.bull.javamelody.SessionListener(); } @Bean public Filter javaMelodyFilter(){ return new net.bull.javamelody.MonitoringFilter(); } 
+5
source share

There is currently documentation available to monitor a Spring-boot application with javamelody, including Spring beans: https://github.com/javamelody/javamelody/wiki/SpringBootStarter

+5
source share

All Articles