Mintondedie 2022-01-19 17:15 采纳率: 100%
浏览 57
已结题

如何使用AOP生成代理对象,程序报错: 无法读取方案文档 'http://www.springframework.org/schema/aop/spring-beans.aop',?

问题遇到的现象和发生背景

当我开启Aspect生成代理对象后aop:aspectj-autoproxy,程序就会出错

问题相关代码,请勿粘贴截图

User类:
@Component
public class User {
    public void add() {
        System.out.println("add.......");
    }
}

增强类:
@Component
@Aspect //生成代理对象
public class UserProxy {
    //前置通知
    //@Before 注解表示作为前置通知
    @Before(value = "execution(* com.fan3.User.add(..))")
    public void before() {
        System.out.println("before.........");
    }
}

测试类:
public class DemoTest {
    @Test
    public void test1(){
        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean5.xml");
        User user = context.getBean("user", User.class);
        user.add();
    }
}


配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!--suppress SpringFacetInspection -->
<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"
       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/aop http://www.springframework.org/schema/aop/spring-beans.aop
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

        <context:component-scan base-package="com.fan3"></context:component-scan>
        <aop:aspectj-autoproxy></aop:aspectj-autoproxy>
</beans
运行结果及报错内容

一月 19, 2022 5:00:54 下午 org.springframework.util.xml.SimpleSaxErrorHandler warning
警告: Ignored XML validation warning
org.xml.sax.SAXParseException; lineNumber: 12; columnNumber: 32; schema_reference.4: 无法读取方案文档 'http://www.springframework.org/schema/aop/spring-beans.aop', 原因为 1) 无法找到文档; 2) 无法读取文档; 3) 文档的根元素不是 xsd:schema

我的解答思路和尝试过的方法

搜索了下都说是版本问题,但我的版本都是比较新的

img

  • 写回答

2条回答 默认 最新

  • CSDN专家-sinJack 2022-01-19 17:22
    关注

    配置文件错了。
    修改如下:

    http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
    

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 1月29日
  • 已采纳回答 1月21日
  • 创建了问题 1月19日

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改