【发布时间】:2015-03-07 01:11:32
【问题描述】:
我正在尝试监视基于 Spring 教程 Building a RESTful Web Service 的 REST 应用程序,但在 Java Melody 文档页面中,配置取决于 web.xml 文件,但 spring 项目没有这样的文件。我尝试使用 java melody 注释并在 WebInitializer 中设置 contextConfigLocation,但是当我进入 Java Melody 页面时,我看不到 Spring 部分。
我有这样的 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);
}
}
我已经按照 Java Melody 文档的说明设置了 contextConfigLocation。
还有我的控制器:
@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 ,它有效!!
标签: spring spring-boot java-melody