解释
通过@Bean注解将创建的对象注入到ioc容器中
例子
@Bean(name = "stringStore", initMethod="init", destroyMethod="destroy")
public Store stringStore() {
return new StringStore();
}
public class StringStore implements Store<String> {
public void init() {
System.out.println("This is init.");
}
public void destroy() {
System.out.println("This is destroy.");
}
}
测试
@Test
public void test() {
Store store = super.getBean("stringStore");
System.out.println(store.getClass().getName());
}
网友评论