报错 1、通配符的匹配很全面, 但无法找到元素 ‘xxxxxx’ 的声明
原因:applicationContext.xml头部的约束不完整
根据提示的标签,在文档头部的 beans 中填入完整的约束
比如,现在报错的是 tx:annotation-driven
那么该标签所需的头部约束为
<beans
。。。。。。省略
<!-- 1、 -->
xmlns:tx="http://www.springframework.org/schema/tx"
<!-- 2、 -->
xsi:schemaLocation="
。。。。。。省略
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
">
报错 2、com.sun.proxy.$Proxy0 cannot be cast to **
aop-config标签中添加属性:proxy-target-class=“true”
<aop:config proxy-target-class="true">
。。。。。。省略
</aop:config>
报错 3、Unknown system variable ‘query_cache_size’
错误原因是mysql-connecter-java版本太低,换一个高版本的即可解决
严格来讲这个错误不应该放到spring标签下,但遇到了还是放上来吧
报错4、The content of element type “web-app” must match “(icon?,display-name?,description?,distributable?,context-param*,filter*,filter-mapping*,listener*,servlet*,servlet-mapping*,session-config?,mime-mapping*,welcome-file-list?,error-page*,taglib*,resource-env-ref*,resource-ref*,security-constraint*,login-config?,security-role*,env-entry*,ejb-ref*,ejb-local-ref*)”.
这么一大坨,是在web.xml文件中遇到的错误
在配置监听器时,顺手将监听器写在了servlet的下面
原因:web.xml中标签顺序不符合web-app_2_3.dtd规范
a、解决方法___1
删除第一行的
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
把问题消灭掉就不会有问题了(滑稽
b、解决方法___2
按规范要求编写web.xml
从提示中可以看到 listener 在servlet 的前面
那就把listener标签写在servlet标签上边
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<!-- 监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- servlet -->
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>top.voidplus.controller.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/TestServlet</url-pattern>
</servlet-mapping>
</web-app>
报错5、org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
**
过程:在servlet中使用 WebApplicationContextUtils.getWebApplicationContext(this.getServletContext()); 加载applicationContext.xml文件
报错提示:在/WEB-INF中加载applicationContext.xml失败
可能的错误:applicationContext.xml的路径配置不正确,或者没配置,也可能是applicationContext的文件名书写错误
**
解决方法
在web.xml文件中,配置applicationContext.xml的正确路径
如:我把它放到了[ META-INF ]文件夹中
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:META-INF/applicationContext.xml</param-value>
</context-param>