我正在尝试按照本教程将配置从xml移到java类:java based config;但是,我的配置类在一个子项目中,而我需要从另一个bean中的bean自动装配......
主要是:ApplicationConfig.java
@Autowired
private InfrastructureConfig infrastructureConfig;
@Bean
public JdbcTemplate jdbcTemplate() {
return new JdbcTemplate(infrastructureConfig.dataSource());
}
我正在尝试从另一个子项目中的applicationContext.xml替换此块:
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
但出于某种原因,这不是自动装配:
@ContextConfiguration(classes={StandaloneInfrastructureConfig.class,QAInfrastructureConfig.class})
@ActiveProfiles("standalone")
@RunWith(SpringJUnit4ClassRunner.class)
public class blahClass implements blahOtherClass {
@Autowired
JdbcTemplate jdbcTemplate;
public List<Blahs> loadBlahs(long id) throws SQLException, IOException {
List<Blahs> blahVar = null;
blahVar=blahThing(jdbcTemplate.getDataSource()).executeBlah(id);
return blahVar;
}
}