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回調函數