我有一个枚举
public enum MyEnum
{
AAA, BBB;
public static final MyEnum findByName(String theName)
{
return MyEnum.valueOf(theName.toUpperCase());
}
}
我将其实例化为:
<bean id="myEnum" class="xxx.MyEnum" factory-method="findByName">
<constructor-arg value="${someProperties}" />
</bean>
并且可以在其他课程中轻松注入:
@Autowired(required = true)
@Qualifier("myEnum")
private MyEnum test;
但我需要使用代理来记录事物。当我把它放到我的app上下文xml:
时<aop:aspectj-autoproxy />
应用程序上下文无法加载,我收到此错误:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [xxx.MyEnum] 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), @org.springframework.beans.factory.annotation.Qualifier(value=myEnum)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1301)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1047)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
... 82 more