@Metered not working on Spring MVC Controller
See original GitHub issueHi there,
I tried to add @Metered
to a Spring MVC Controller but do not get any metrics. I read the section about Spring AOP limitations but not sure if this the problem in this case.
My Spring configuration below and the annotations I added to the controller method. Is there any other configuration or annotations required to make this work?
<metrics:metric-registry id="metrics" />
<metrics:health-check-registry id="healthCheck" />
<metrics:annotation-driven metric-registry="metrics" health-check-registry="healthCheck" />
<metrics:reporter type="slf4j" metric-registry="metrics" period="1m" />
<metrics:register metric-registry="metrics">
<bean metrics:name="jvm.gc" class="com.codahale.metrics.jvm.GarbageCollectorMetricSet" />
<bean metrics:name="jvm.memory" class="com.codahale.metrics.jvm.MemoryUsageGaugeSet" />
</metrics:register>
and my MVC Controller is annotated like this:
@Controller
public class BlaController {
@Timed
@Counted
@Metered
@ResponseBody
@RequestMapping(value = "bla", method = RequestMethod.POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
public SomeResponse bla(@RequestBody Request request) {
// do something I want to measure
}
}
Many thanks for pointers. Niels
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How do i fix my controller not working in spring mvc?
Your Java code is right, but first you need to make sure that there is 'user' in the session, probably when logging in,...
Read more >Quick Guide to Spring Controllers - Baeldung
A quick and practical guide to Spring Controllers - both for typical MVC apps and for REST APIs.
Read more >Getting Started | Serving Web Content with Spring MVC
In Spring's approach to building web sites, HTTP requests are handled by a controller. You can easily identify the controller by the @Controller...
Read more >[FIXED] Spring MVC Faulty URL Root cause Analysis - YouTube
Welcome to another spring MVC framework tutorial for beginners where I will be solving your issues with examples, This video is recorded ...
Read more >Troubleshooting Spring MVC RequestMapping - YouTube
In this video I troubleshoot a problem with how the RequestMapping is configured in Spring MVC. A student of mine was having a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks a million, I did have indeed a subcontext in my web application. Adding the
<metrics:annotation-driven />
element to the dispatcher context did the trick. Do you think it would be worth adding a little note about this to the README? Somethign like below:If your spring application uses nested spring contexts and each context loads classes annotated with metrics annotations, add the
<metrics:annotation-driven />
directive to each spring context configuration. This will ensure all metrics annotated classes are registered for metrics collection. A typical example is a spring mvc web application. You may configure the metrics registry and reporters in the main web application context whilst metered controllers are defined in the dispatch servlet context.the application wide context file
applicationContext.xml
contains the metrics setup and may also load metered services:and in the dispatcher servlet specific context file
api-v1-dispatcher-servlet.xml
repeat the annotation driven configuration:I had a similar issue. This saved my day!