'Autowire does not work with ImportResource
I have the following test case parent class. It is abstract class with the test class extending this class. The Autowire on Registry class cannot find the bean definition even though it is defined in beans1.xml.
How to fix this?
@RunWith(SpringJUnit4ClassRunner.class)
@TestPropertySource("classpath:application.properties")
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@TestExecutionListeners({
DependencyInjectionTestExecutionListener.class,
DirtiesContextTestExecutionListener.class,
TransactionalTestExecutionListener.class
})
@ImportResource( locations = { "classpath:beans/beans1.xml", "classpath:beans2.xml" } )
@ContextConfiguration(classes = {ConfigClass1.class,
ConfigClass2.class})
public abstract class TestBaseIT {
@Autowired
protected Registry registry;
..
}
The Registry definition is in beans1.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="registry" class="com.company.Registry">
</bean>
</beans>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
