Ich versuche eine REST-Anwendung basierend auf dem Spring Tutorial Building a RESTful Web Service zu überwachen, aber auf der Java Melody Dokumentationsseite hängt die Konfiguration von der web.xml Datei ab, aber das Spring Projekt habe keine solche Datei. Ich habe versucht, indem ich Java-Melodie Annotationen und ContextConfigLocation im WebInitializer setzen, aber wenn ich auf Java Melody Seite eingeben, kann ich nicht sehen Frühling Abschnitt.Überwachung von Spring Beans mit JavaMelody im Spring-Boot Projekt
Ich habe meine WebInitializar wie folgt aus:
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);
}
}
Ich sagte die contextConfigLocation als Java Melody Dokumentation festgelegt haben.
Und mein 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));
}
}
Jede Beratung es funktioniert?
Fügen Sie einfach '@ImportResource (" Klassenpfad: net/bull/javamelody/monitoring-spring.xml ")' zu Ihrer 'Application.class' hinzu. –
Danke @ M.Deinum, es funktioniert !! – gamerkore