2

we have an application using Spring and Jersey web services, it's not a Spring boot nor spring mvc app. I want to plugin spring actuator to the project. by following different post online, I was able add spring-actuator to the pom file and create Jersey resource that call Spring-actuator endpoints, but it wont' work.

here is what I added in the pom file:

  <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-actuator</artifactId>
      <version>1.3.5.RELEASE</version>
  </dependency>

and here is my resource code:

@Component
//@EnableAutoConfiguration  <-- here is the trouble
@Path("/actuator")
public class ActuatorResource extends AbstractResource {
    @Autowired
    private HealthEndpoint health;
    @Autowired
    private MetricsEndpoint metrics;

    @Inject
    public ActuatorResource(@Named("authorization") Authorization authorization) {
        super(authorization);
    }

    @GET
    @Path("/health")
    public Object getHealth() {
        return health.invoke();
    }

    @GET
    @Path("/metrics")
    public Object getMetrics() {
        return this.metrics.invoke();
    }
}

with the annotation '@EnableAutoConfiguration' I got this error:

Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
    at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724) ~[na:1.8.0_111]
    at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531) ~[na:1.8.0_111]
    at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355) ~[na:1.8.0_111]
    at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286) ~[na:1.8.0_111]
    at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120) ~[na:1.8.0_111]
    at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72) ~[na:1.8.0_111]
    at java.lang.Class.createAnnotationData(Class.java:3521) ~[na:1.8.0_111]
    at java.lang.Class.annotationData(Class.java:3510) ~[na:1.8.0_111]
    at java.lang.Class.getAnnotations(Class.java:3446) ~[na:1.8.0_111]
    at org.springframework.core.type.classreading.AnnotationAttributesReadingVisitor.registerMetaAnnotations(AnnotationAttributesReadingVisitor.java:257) ~[spring-core-3.2.18.RELEASE.jar:3.2.18.RELEASE]
    at org.springframework.core.type.classreading.AnnotationAttributesReadingVisitor.doVisitEnd(AnnotationAttributesReadingVisitor.java:251) ~[spring-core-3.2.18.RELEASE.jar:3.2.18.RELEASE]
    at org.springframework.core.type.classreading.RecursiveAnnotationAttributesVisitor.visitEnd(AnnotationAttributesReadingVisitor.java:173) ~[spring-core-3.2.18.RELEASE.jar:3.2.18.RELEASE]
    at org.springframework.asm.ClassReader.a(Unknown Source) ~[spring-core-3.2.18.RELEASE.jar:3.2.18.RELEASE]

if I comment out '@EnableAutoConfiguration', I got this error

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.boot.actuate.endpoint.HealthEndpoint; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.boot.actuate.endpoint.HealthEndpoint] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
..

How can I enable '@EnableAutoConfiguration' but don't get that TypeNotPresentExceptionProxy error? thanks.

user468587
  • 4,799
  • 24
  • 67
  • 124

0 Answers0