0
就在最近开始寻找到春天特别是其最新的功能,如Java配置等 我有这个有些奇怪的问题:的Spring Java基础配置“鸡和蛋的问题”
Java的配置段:
@Configuration
@ImportResource({"classpath*:application-context.xml","classpath:ApplicationContext_Output.xml"})
@Import(SpringJavaConfig.class)
@ComponentScan(excludeFilters={@ComponentScan.Filter(org.springframework.stereotype.Controller.class)},basePackages = " com.xx.xx.x2.beans")
public class ApplicationContextConfig extends WebMvcConfigurationSupport {
private static final Log log = LogFactory.getLog(ApplicationContextConfig.class);
@Autowired
private Environment env;
@Autowired
private IExtendedDataSourceConfig dsconfig;
@PostConstruct
public void initApp() {
...
}
@Bean(name="transactionManagerOracle")
@Lazy
public DataSourceTransactionManager transactionManagerOracle() {
return new DataSourceTransactionManager(dsconfig.oracleDataSource());
}
IExtendedDataSourceConfig具有其基于弹簧有效简表的一个或另一个中实例化的两种实现方法。对于这个例子让说这是执行:
@Configuration
@PropertySources(value = {
@PropertySource("classpath:MYUI.properties")})
@Profile("dev")
public class MYDataSourceConfig implements IExtendedDataSourceConfig {
private static final Log log = LogFactory.getLog(MYDataSourceConfig.class);
@Resource
@Autowired
private Environment env;
public MYDataSourceConfig() {
log.info("creating dev datasource");
}
@Bean
public DataSource oracleDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("oracle.jdbc.driver.OracleDriver");
dataSource.setUrl(env.getProperty("oracle.url"));
dataSource.setUsername(env.getProperty("oracle.user"));
dataSource.setPassword(env.getProperty("oracle.pass"));
return dataSource;
}
的问题是,当transactionManagerOracle
豆被调用时,(即使我尝试将其标记为懒惰)dsconfig
变量值显示为空。
我想@beans
先处理,然后全部Autowire
s,有没有解决这个问题?如何既跟春天创造豆之前注入dsconfig
变量,或以某种方式创建dsconfig
后@beans
注入?