做spring测试时只使用了@Component,为什么出现要求@Configuration注解呢

霸都城管 发布于 2015/03/16 17:35
阅读 4K+
收藏 0
java.lang.IllegalStateException: CGLIB is required to process @Configuration classes. Either add CGLIB to the classpath or remove the following @Configuration bean definitions: [aspectJCachingConfiguration, springConfiguredConfiguration, aspectJAsyncConfiguration, aspectJTransactionManagementConfiguration, proxyCachingConfiguration, loadTimeWeavingConfiguration, proxyAsyncConfiguration, schedulingConfiguration, proxyTransactionManagementConfiguration, delegatingWebMvcConfiguration]
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:352)
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:246)
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687)
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:626)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
	at org.testfirst.testSpring.<init>(testSpring.java:14)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
	at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:195)
	at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:244)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:241)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

只是使用了@Component,按教程来的,应该不是其他问题

加载中
0
OSC_代码审查官
OSC_代码审查官
是否缺少
<aop:aspectj-autoproxy proxy-target-class="true" />
?
0
霸都城管

引用来自“半个朋友”的评论

是否缺少
<aop:aspectj-autoproxy proxy-target-class="true" />
?

还没看到aop,就是先做一个简单的annotation注入测试,bean文件


和讲解代码对比了下,也没发现什么问题

0
霸都城管
<beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:context="http://www.springframework.org/schema/context"
     xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
         http://www.springframework.org/schema/context
         http://www.springframework.org/schema/context/spring-context-3.0.xsd">
   <!-- 打开Spring的Annotation支持 -->
   <context:annotation-config/>
   <!-- 设定Spring 去哪些包中找Annotation -->
   <context:component-scan base-package="org"/>
          
</beans>
0
霸都城管

找到原因了,我注解的类在org.action,org.service等包下,必须多次添加

<context:component-scan base-package="org.action"/>

<context:component-scan base-package="org.dao"/>
<context:component-scan base-package="org.model"/>
<context:component-scan base-package="org.service"/>
问题解决,那现在问题是这不是自动扫描吗,为什么隔开一个包就不行,这样添加好麻烦呐

0
HostSugar
HostSugar

引用来自“霸都城管”的评论

找到原因了,我注解的类在org.action,org.service等包下,必须多次添加

<context:component-scan base-package="org.action"/>

<context:component-scan base-package="org.dao"/>
<context:component-scan base-package="org.model"/>
<context:component-scan base-package="org.service"/>
问题解决,那现在问题是这不是自动扫描吗,为什么隔开一个包就不行,这样添加好麻烦呐

直接<context:component-scan/> 

or <context:component-scan base-package="org.action,org.dao"/>

0
霸都城管

引用来自“霸都城管”的评论

找到原因了,我注解的类在org.action,org.service等包下,必须多次添加

<context:component-scan base-package="org.action"/>

<context:component-scan base-package="org.dao"/>
<context:component-scan base-package="org.model"/>
<context:component-scan base-package="org.service"/>
问题解决,那现在问题是这不是自动扫描吗,为什么隔开一个包就不行,这样添加好麻烦呐

引用来自“东门吹风”的评论

直接<context:component-scan/> 

or <context:component-scan base-package="org.action,org.dao"/>

亲测<context:component-scan/> 会抛出base-package是必须元素异常,

<context:component-scan base-package="org.action,org.dao"/>可以,这是什么原因导致的呢?

HostSugar
HostSugar
可能我记错了,必须要加base-package,多个包用逗号隔开。估计你之前的包org 可能是目录不够深不构成包名
返回顶部
顶部