SpringIOC容器要使用注解配置Bean,那么必须要有aop的jar包
用于表示Bean的注解主要有一下四种
@Component
@Service
@Controller
@Repository
光光加上注解是没有用的,还需要在xml文件中对这些注解进行扫描,xml扫描配置如下
这里的base-package表示Spring只会扫描com.llf.annotation.bean这个包以及其子包中的类关于上面的四个注解
<context:component-scan base-package="com.llf.annotation.bean"></context:component-scan>
这四个注解中间可以加Value属性,表示其在SpringIOC容器中的名字,也就是getBean方法中的参数。
context:component-scan这个标签还有很多属性,用来各种要求取扫描,可以参考:
SpringIOC容器-使用注解配置Bean-xml扫描注解
原文:https://www.cnblogs.com/linglongfang/p/12727451.html