ryantenney / metrics-spring

Spring integration for Metrics
http://www.ryantenney.com/metrics-spring/
Apache License 2.0
701 stars 226 forks source link

No default constructor error while using spring 4.1.7 jars #194

Closed mayankbtechit2011 closed 7 years ago

mayankbtechit2011 commented 7 years ago

Hi Team,

I have developed a Hello World project for using dropwizrd metrics for sending stats to Graphite. I have used ryantenny metrics- spring also because I have to use this project learning in a Spring based web application.

My project jars versions

My resource file:

package com.springservice.controller;

import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response;

import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;

import com.codahale.metrics.Meter; import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.annotation.Timed;

@RestController public class MyResource {

MetricRegistry metrics;
Meter requestCount;

public MyResource(MetricRegistry registry) {
    this.metrics = registry;
    requestCount = metrics.meter(MetricRegistry.name("requestCount"));
}

@RequestMapping("/hello")
@Produces(MediaType.TEXT_PLAIN)
@Timed(absolute=true, name="helloRuntime")
public Response handleRequest() {
    requestCount.mark();
    return Response.ok("Hello World").build(); 
}

@RequestMapping("/Hi")
@Produces(MediaType.TEXT_PLAIN)
@Timed(absolute=true, name="hiRuntime")
public Response hiRequest() {
    requestCount.mark();
    return Response.ok("Hi World").build(); 
}

}

Spring configuring class:

package com.springservice.controller;

import java.net.InetSocketAddress; import java.util.concurrent.TimeUnit; import org.springframework.context.annotation.Configuration; import com.codahale.metrics.ConsoleReporter; import com.codahale.metrics.MetricFilter; import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.graphite.Graphite; import com.codahale.metrics.graphite.GraphiteReporter; import com.ryantenney.metrics.spring.config.annotation.EnableMetrics; import com.ryantenney.metrics.spring.config.annotation.MetricsConfigurerAdapter;

@Configuration @EnableMetrics public class SpringConfiguringClass extends MetricsConfigurerAdapter {

@Override
public void configureReporters(MetricRegistry metricRegistry) {

    final Graphite graphite = new Graphite(new InetSocketAddress("10.164.XX.XXX", 2003));
    final GraphiteReporter reporter = GraphiteReporter.forRegistry(metricRegistry)
            .prefixedWith("scc")
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .filter(MetricFilter.ALL)
            .build(graphite);
    reporter.start(5, TimeUnit.SECONDS);
        }

}

mayankbtechit2011 commented 7 years ago

Got solution,

I was not using @Autowired annotation before the argument constructor.