ryantenney / metrics-spring

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

Unable to use @EnableMetrics in an auto configuration class #165

Open nickcodefresh opened 8 years ago

nickcodefresh commented 8 years ago

I'm trying to create a spring boot autoconfiguration library that enables metrics publication by fault in my microservices. My auto config class is defined as

@Configuration
@ConditionalOnWebApplication
@EnableMetrics
@Slf4j
public class GraphiteMetricsPublishingAutoConfiguration extends MetricsConfigurerAdapter {

but it doesn't publish metrics unless I add @EnableMetrics to the application class of the application itself. The class is called though. Any ideas why?

Thanks

Nick

lazee commented 8 years ago

You should be able to solve it like this...

@Configuration
@ConditionalOnWebApplication
@Slf4j
public class GraphiteMetricsPublishingAutoConfiguration extends MetricsConfigurerAdapter {

    @Configuration
    @EnableMetrics
    @ComponentScan(basePackages = {"com.ryantenney"})
    public static class SpringMetricsConfiguration {
    }
}
ryantenney commented 8 years ago

ComponentScan in your example is not necessary.

steklopod commented 6 years ago

Didn't fixed :-( Caused by: java.io.FileNotFoundException: class path resource [com/ryantenney/metrics/spring/config/annotation/MetricsConfigurerAdapter.class] cannot be opened because it does not exist