将我的 spring 上下文配置移入后src/main/resources/META-INF/spring
,我无法连接我的 bean。在我的 spring 上下文直接放在 src 文件夹下之前,我的测试和自动装配运行良好:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath*:cmn-dao-context.xml" })
@Transactional
public class ComplaintDaoTest extends TestCase {
@Autowired
private ComplaintDao mComplaintDao;
错误:
09.12.2013 23:30:02 org.springframework.test.context.TestContextManager prepareTestInstance
SCHWERWIEGEND: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@873723] to prepare test instance [null(de.bc.qz.dao.ComplaintDaoTest)]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'de.bc.qz.dao.ComplaintDaoTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.bc.qz.dao.ComplaintDao de.bc.qz.dao.ComplaintDaoTest.mComplaintDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [de.bc.qz.dao.ComplaintDao] 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)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
数据库属性:
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>database.properties</value>
</property>
</bean>
有人可以帮我吗?