|
元素名
|
元素类型
|
说明
|
默认值
|
取值说明
|
|
|
String[]
|
Bean的别名
|
{}
|
|
|
|
DependencyCheck
|
默认依赖检查方式
|
DependencyCheck. UNSPECIFIED ,即不进行依赖检查
|
|
|
|
boolean
|
允许覆盖xml或其它Configuration的bean
|
false
|
|
|
|
AutoWire
|
自动织入方式
|
INHERITED
|
Autowire
|
|
|
String[]
|
当前Bean依赖的bean
|
{}
|
|
|
|
String
|
销毁方法名
|
空
|
|
|
|
String
|
初始化方法名
|
空
|
|
|
|
Lazy
|
延时初始化策略
|
UNSPECIFIED
|
|
|
|
|
当前bean的元数据
|
{}
|
|
|
|
String
|
Bean的作用域
|
singleton
|
Singleton,prototype或自定义作用域
|
@Bean
public ExampleBean exampleBean() ...{
return ExampleFactory.createBean();
}
![]()
当用方法来定义一个Bean时,这个方法必须是public的。
示例:使用aliases元素。,定义一个Bean,别名为hello
@Bean(aliases=...{"hello"})
public HelloWorld helloWorld()...{
HelloWorld helloWorld = new HelloWorld();
helloWorld.setWord(word());
return helloWorld;
}
public static void main(String[] args)...{
ApplicationContext context = new AnnotationApplicationContext(ConfigurationFull.class.getName());
HelloWorld hello = (HelloWorld)context.getBean("hello");
hello.sayHello();
}