目录
Aspect cannot be resolved to a type
(2) 配置spring-idol.xml中引入aop名称空间
(3):配置spring-idol.xml中开启aop注解扫描,如下配置所示:
Aspect cannot be resolved to a type
注解切面方式实现aop编程
开发步骤
(1) 先引入aop相关的jar文件
AspectJ项目地址为:http://www.eclipse.org/aspectj/,打开项目后,点击其中的Download链接,然后选择合适的版本,下载后得到为一个Jar包,例如aspectj-1.8.5.jar。将jar包解开,可以发现其中有lib目录,其中包含aspectjrt.jar、aspectjtools.jar、aspectjweaver.jar和org.aspectj.matcher.jar几个jar包文件,将它们加入到项目的eclipse的build path中,就可以进行面向切面的项目开发了。
Aopalliance包可以到Jboss的软件库:https://repository.jboss.org/nexus/content/repositories/root_repository/aopalliance/进行下载,下载后得到aopalliance包,直接添加到项目的build path中就可以了。其实上面的AspectJ支持包也可以在https://repository.jboss.org中找到
jar文件(aspectj-1.9.2.jar)的百度网盘连接:链接: https://pan.baidu.com/s/1VbCFam-_Of19b4S5qoUmYA 提取码:n6xu
(2) 配置spring-idol.xml中引入aop名称空间
技巧:找到文件spring-framework-3.2.5.RELEASE/docs/spring-framework-reference/htmlsingle打开index.html搜索xmlns:aop然后找到下面红色三句话,分别拷贝到bean.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:util="http://www.springframework.org/schema/util"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="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/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
</bean>
(3):配置spring-idol.xml中开启aop注解扫描,如下配置所示:
<?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:util="http://www.springframework.org/schema/util"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="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/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 开启注解扫描 -->
<context:component-scan base-package = "com.springinaction.springidol"></context:component-scan>
<!-- 开启aop注解方式,默认为false -->
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
</bean>