javaweb——spring第三坑(报错记录

报错 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>

在这里插入图片描述

PS:暂时只有这些,后续遇到其他问题会在本篇更新

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值