完全注解开发
创建配置类:SpringConfig类
@Configuration//作为配置类,替代xml配置文件
@ComponentScan(basePackages = {"com.feng"})//开启注解扫描<context:component-scan base-package="com.feng"></context:component-scan>
public class SpringConfig {
}
测试类
@Test
public void test2(){
ApplicationContext context =
new AnnotationConfigApplicationContext(SpringConfig.class);
UserService userService = context.getBean("userService",UserService.class);
userService.add();
}