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?
spring spring-boot java-melody
gamerkore
source share