小编gam*_*ore的帖子

在Spring-Boot项目中使用JavaMelody监视spring bean

我正在尝试基于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)

有什么建议让它起作用吗?

spring java-melody spring-boot

7
推荐指数
2
解决办法
6669
查看次数

标签 统计

java-melody ×1

spring ×1

spring-boot ×1