1、除spring基本包外还需要下载AOP包

spring-aop-4.2.4.RELEASE.jar

 

2、导入约束(最后两行)

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:contexnt="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-2.5.xsd">

 

3、指定注释自动扫描的包,自动注入包中有注解的类

<contexnt:component-scan base-package="org.helloworld"></contexnt:component-scan>

 

4、在扫描的类上加入注释标签

@Component、@Service等等

 

5、注入引用

@Autowired   自动注释
@Resource(name = "user") 指定名称

备注:也可以XML配置和注释混合使用

 

相关文章:

  • 2021-12-04
  • 2021-05-08
  • 2021-12-06
  • 2021-06-07
  • 2022-12-23
  • 2021-11-21
  • 2021-10-24
猜你喜欢
  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
  • 2021-09-04
  • 2022-12-23
  • 2021-09-11
  • 2022-03-01
相关资源
相似解决方案