我们有一个使用Spring和Jersey Web服务的应用程序,它不是Spring启动也不是spring mvc应用程序。我想将弹簧执行器插入到项目中。通过在线跟踪不同的帖子,我可以在pom文件中添加spring-actuator并创建称为Spring-actuator端点的Jersey资源,但它不会工作。
这是我在pom文件中添加的内容:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
<version>1.3.5.RELEASE</version>
</dependency>
这是我的资源代码:
@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();
}
}
注释'@EnableAutoConfiguration'我收到此错误:
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]
如果我注释掉'@EnableAutoConfiguration',我就会收到此错误
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)}
..
如何启用'@EnableAutoConfiguration'但是没有得到TypeNotPresentExceptionProxy错误?感谢。