1.配置类注解@Configuration.java
2.Bean注解 @Bean.spring
3.导入其余配置类@Import.函数
4.回调函数spa
@Bean(initMethod = "init", destroyMethod = "cleanup" )
5.做用范围prototype
@Scope("prototype") code
6.例子htm
public static void main(String[] args) { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(AppConfig.class, OtherConfig.class); ctx.register(AdditionalConfig.class); ctx.refresh(); MyService myService = ctx.getBean(MyService.class); myService.doStuff(); }
或者经过注解引入blog
@ContextConfiguration(classes = {PersistenceConfig.class, CoreConfig.class}) get
refer to: http://www.tutorialspoint.com/spring/spring_java_based_configuration.htm回调函数