了解一下spring注入的一些規(guī)則
@Configuration
public class BeanConfig {
@Bean
public Budget budget(){
Budget budget = new Budget();
budget.setCompany("牛逼科技");
return budget;
}
@Bean(name="budget1")
public Budget budget23(){
Budget budget = new Budget();
budget.setCompany("牛逼科技");
return budget;
}
@Bean
public Budget budget2(){
Budget budget = new Budget();
budget.setCompany("牛逼科技123123");
return budget;
}
這兩個(gè)bena的注入寫法是
@Autowired
Budget budget;
@Autowired
@Qualifier("budget2")
Budget budget2;
@Autowired
@Qualifier("budget1")
Budget budget1;
@Bean注解里面有個(gè)name字段战授,如果你申明了慕淡,那么bean的name會(huì)按照你申明的注入秘狞,沒有聲明會(huì)按照默認(rèn)的名稱(方法名類名首字母小寫)注入
localSessionFactoryBean.setPackagesToScan("com.cmcmc");
ApplicationContext applicationContext = SpringContextAware.getApplicationContext();
DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory)applicationContext.getAutowireCapableBeanFactory();
beanFactory.applyBeanPostProcessorsAfterInitialization(localSessionFactoryBean, localSessionFactoryBean.getClass().getName());
beanFactory.registerSingleton(localSessionFactoryBean.getClass().getName(), localSessionFactoryBean);
如圖我們實(shí)現(xiàn)了動(dòng)態(tài)修改bean