Spring配置笔记

maven导入spring配置

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>5.0.4.RELEASE</version>
</dependency>
<dependency> //支持aop的包---第三方aspectj
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjweaver</artifactId>
    <version>1.9.4</version>
</dependency>

applicationContext.xml头部配置信息

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop" //4
       xmlns:p="http://www.springframework.org/schema/p" //1
       xmlns:c="http://www.springframework.org/schema/c" //2
       xmlns:context="http://www.springframework.org/schema/context"  //3
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        https://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context  //3
        http://www.springframework.org/schema/context/spring-context.xsd  //3
        http://www.springframework.org/schema/aop //4
        http://www.springframework.org/schema/aop/spring-aop.xsd"> //4
        
    <context:component-scan base-package="com.jarvis"/>  //5
    <context:annotation-config/>  //3   有了5,可删除该句
    <!--开启基于注解的AOP功能:aop名称空间
    proxy-target-class="true":表示使用CGLib动态代理技术织入增强。
    如果proxy-target-class设置为true,但是目标类没有声明接口,
    则spring将自动使用CGLib动态代理。-->
    <aop:aspectj-autoproxy  proxy-target-class="true" />
  1----p命名空间注入
  2----c命名空间注入
  3----用于激活那些已经在spring容器里注册过的bean上面的注解,如使用@AutoWired等自动装配
  4----aop使用
  5----扫描包,该包下的@Service,@Component,@Repository,@Controller等这些注解的类,则把这些类注册为bean 
</beans>

spring配置注解context:annotation-config和context:component-scan区别
参考:https://blog.csdn.net/fox_bert/article/details/80793030

(1)< context:annotation-config />:仅能够在已经在已经注册过的bean上面起作用。 对于没有在spring容器中注册的bean,它并不能执行任何操作。
(2)< context:component-scan base-package=“XX.XX”/> :除了< context:annotation-config />具有的功能之外,还具有自动将带有@component,@service,@Repository等注解的对象注册到spring容器中的功能。
因此当使用 < context:component-scan/> 后,就可以将 < context:annotation-config/> 移除了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值