package com.wisely.spring4_2.imp;
public class DemoService {
public void doSomething(){
System.out.println("everything is all fine");
}
}
package com.wisely.spring4_2.imp;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@Configuration
@Import(DemoService.class)//在spring 4.2之前是不不支持的
public class DemoConfig {
}
package com.wisely.spring4_2.imp;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class Main {
public static void main(String[] args) {
AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext("com.wisely.spring4_2.imp");
DemoService ds = context.getBean(DemoService.class);
ds.doSomething();
}
}
输出结果
everything is all fine
原文:http://wiselyman.iteye.com/blog/2217077