spring配置文件无法使用aop:config标签
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
今天学习面向切面编程的时候,在spring配置文件中使用aop:config标签时没有自动提示,但我没管,直接敲上去,启动tomcat的时候发现了异常:
Line 23 in XML document from file [C:\apache-tomcat-8.5.43\wtpwebapps\cs20200802_cloud_note\WEB-INF\classes\conf\spring-aop.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 23; columnNumber: 14; 元素 “aop:config” 的前缀 “aop” 未绑定。
提示:以下是本篇文章正文内容,下面案例可供参考
一、异常出现
异常一、元素 “aop:config” 的前缀 “aop” 未绑定:
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 23 in XML document from file [C:\apache-tomcat-8.5.43\wtpwebapps\cs20200802_cloud_note\WEB-INF\classes\conf\spring-aop.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 23; columnNumber: 14; 元素 "aop:config" 的前缀 "aop" 未绑定。
异常二、通配符的匹配很全面, 但无法找到元素 ‘aop:config’ 的声明:
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 25 in XML document from file [C:\apache-tomcat-8.5.43\wtpwebapps\cs20200802_cloud_note\WEB-INF\classes\conf\spring-aop.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 25; columnNumber: 14; cvc-complex-type.2.4.c: 通配符的匹配很全面, 但无法找到元素 'aop:config' 的声明。
二、解决办法
在spring配置文件的 头部beans中添加
xmlns:aop=“http://www.springframework.org/schema/aop”
和
xsi:schemaLocation=“http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd”:
代码如下:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
同时满足这两项配置,就可以解决一下两个问题:
-
元素 “aop:config” 的前缀 “aop” 未绑定
-
通配符的匹配很全面, 但无法找到元素 ‘aop:config’ 的声明。
总结
这里对文章进行总结:
以上就是今天要讲的内容,本文仅仅介绍了spring配置文件中无法使用 aop:config标签的原因和解决办法。
出错不可怕,怕的是不会找解决方法,有问题找度娘。