把一个对象放到spring容器中
1.FactoryBean
@Component
public class MyFactoryBean implements FactoryBean {
@Override
public Object getObject() throws Exception {
return null;//返回一个bean
}
@Override
public Class<?> getObjectType() {
return null;//类的类型
}
@Override
public boolean isSingleton() {
return false;
}
}
2.registerSingle
AnnotationConfigApplicationContext.getBeanFactory().registerSingleton( "xx",new XXXX() );
3.@Bean
@Bean
public IndexDao indexDao(){
return new IndexDao();
}
网友评论