我正在尝试基于Spring教程构建RESTful Web服务来监视REST应用程序,但在Java Melody文档页面中,配置依赖于web.xml文件,但spring项目没有这样的文件.我尝试使用java旋律注释并在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);
}
}
Run Code Online (Sandbox Code Playgroud)
我已经将contextConfigLocation设置为Java Melody文档所说的.
而我的控制器:
@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));
}
}
Run Code Online (Sandbox Code Playgroud)
有什么建议让它起作用吗?