初探Spring——采用配置类与注解方式
在上一讲的项目基础上继续。
不仅采用注解方式,而且用配置类替换Spring配置文件。
1、将xml_annotation包里的两个接口和四个类拷贝到annotation包里
maven java?
2、创建Spring配置类来取代Spring配置文件(spring-config.xml)
@Configuration声明当前类是一个配置类,相当于一个Spring配置文件。
@ComponentScan,自动扫描包名下所有使用@Service、@Component、@Repository、@Controller的类,并注册为Bean。
( @ComponentScan( "net.hw.spring.ch1.annotation") 相当于Spring配置文件里的< context :component-scan