<context:annotation-config/>
- 这个出现在Spring的applicationContext.xml配置文件中
- 主要到目的是开启 将bean对象中包含的其他bean对象装配到当先bean中的功能
- @Autowired 标注了那个属性是需要被装配的
- @Resource 和@Autowired 一样也是标注那个属性是需要被装配的
- 用于激活那些已经在spring容器里注册过的bean
- <context:component-scan/>具有相同的功能
@Autowired
- @Autowired属于DI的实现
- @Autowired出现在类对象的属性上或者这个属性的setter方法上
- @Autowired和<context:annotation-config/>配合实现的自动装配
- @Autowired属于springframework框架的类
- @Autowired注解是按照类型(byType)装配依赖对象,默认情况下它要求依赖对象必须存在
- @Autowired如果我们想使用按照名称(byName)来装配可以在后面加上@Qualifier("className")
@Resource
- @Resource属于DI的实现
- @Resource出现在类对象的属性上或者这个属性的setter方法上
- @Resource和<context:annotation-config/>配合实现的自动装配
- @Resource属于javax包的类
- @Resource要想指定具体实现类可以在后面加上@Resource(name="className")
- 使用name属性,则使用byName的自动注入策略,而使用type属性时则使用byType自动注入策略。如果既不制定name也不制定type属性,这时将通过反射机制使用byName自动注入策略。
<context:component-scan base-package="com.yinyi.pojo"/>
- <context:component-scan base-package="com.yinyi.pojo"/>是开启对Bean进行注解配置
- com.yinyi.pojo是需要装载的Bean对象的包地址
- <context:component-scan base-package="com.yinyi.pojo"/>和@Component配合使用
- 如果在标签中添加<context:include-filter type="annotation"
expression="org.springframework.stereotype.Controller" />ispatcherServlet上下文, 只管理@Controller类型的bean, 忽略其他型的bean, 如@Service
@Component
- 为类加上@Component注解,表示这是一个bean,由Spring进行管理
- @Component属于ioc的实现
<aop:aspectj-autoproxy/>
- 找到被注解了的切面类,进行切面配置
- 与@Aspect和@Around相关
@Aspect
- 表示这是一个切面
- 出现在切面Class头上一般随后跟着@Component
- AOP的实现
@Around
- 标记在有ProceedingJoinPoint参数的方法上
- 一般写法是
@Around(value = "execution(* com.yinyi.service.ProductService.*(..))")
这表示对满足如下条件的方法调用,进行切面操作:
* 返回任意类型
com.yinyi.service.ProductService.* 包名以 com.yinyi.service.ProductService 开头的类的任意方法
(..) 参数是任意数量和类型