spring 自动扫描bean

该文章只供自己参考,对其他人没帮助,别浪费您的时间!

1.在applicationContext.xml中加入context的命名空间和对应的schemaLocation

xmlns:context="http://www.springframework.org/schema/context"

xsi:schemaLocation="????" 在前一个schema后面空格加上http://www.springframework.org/schema/context    
                     http://www.springframework.org/schema/context/spring-context-2.5.xsd   (它是以键值对存在的)

2.添加<context:annotation-config/>在对应的类中用@Service 注解此类

3.添加组建扫描<context:component-scan base-package="com.test.model"></context:component-scan>

详:见项目springTest

原文地址:https://www.cnblogs.com/yanjunwu/p/3000487.html