我試圖監視基於Spring教程Building a RESTful Web Service的REST應用程序,但在Java Melody文檔頁面中配置依賴於web.xml文件,但是spring項目會沒有這樣的文件。我嘗試通過使用java旋律註釋並在WebInitializer中設置contextConfigLocation,但是當我進入Java旋律頁面時,我看不到Spring部分。在Spring-Boot項目中使用JavaMelody監視spring beans
我有我的WebInitializar這樣的:
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);
}
}
我已經設置contextConfigLocation的作爲Java旋律文檔說。
而且我的控制器:
@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));
}
}
任何意見,使其工作?
只需將'@ImportResource(「classpath:net/bull/javamelody/monitoring-spring.xml」)''添加到'Application.class'中。 –
謝謝@ M.Deinum,它的工作原理! – gamerkore