Caused by: java.lang.IllegalArgumentException: Invalid <url-pattern> [url] in servlet mapping

使用SSM框架的时候我测试springmvc的时候遇到的错误:
一、Server Tomcat v9.0 Server at localhost failed to start.
启动Tomcat服务的时候报错信息:
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/testSSM_2020_12_04_Evening_classes]] at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
Caused by: java.lang.IllegalArgumentException: Invalid <url-pattern> [url] in servlet mapping
错误原因: servlet-mapping中的url-pattern的 url 忘记改写为 /
我的web.xml配置文件是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
	
	<!-- needed for ContextLoaderListener -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:applicationContext.xml</param-value>
	</context-param>

	<!-- Bootstraps the root web application context before servlet initialization -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	
	<!-- The front controller of this Spring Web application, responsible for handling all application requests -->
	<servlet>
		<servlet-name>springDispatcherServlet</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>/WEB-INF/springmvc.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<!-- Map all requests to the DispatcherServlet for handling -->
	<servlet-mapping>
		<servlet-name>springDispatcherServlet</servlet-name>
		<url-pattern>url</url-pattern>
	</servlet-mapping>
	
	
</web-app>

解决办法:把错误原因改写为下面的

	<servlet-mapping>
		<servlet-name>springDispatcherServlet</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
	

二、当我解决前一个问题,可以正常启动之后又有这个错误了:HTTP Status 404 – 未找到
报错信息:[org.springframework.web.context.ContextLoaderListener] org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in class path resource [applicationContext.xml]: Could not resolve placeholder 'jdbc.driver' in value "${jdbc.driver}"; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'jdbc.driver' in value "${jdbc.driver}"
原因:我写的数据库连接的外部文件db.properties的Driver是这样的:
jdbc.jdbcDriver=com.mysql.jdbc.Driver
但是我spring配置文件调用的时候是这样写的:

<property name="driverClass" value="${jdbc.driver}"></property>

这其中jdbc.Driver和jdbc.driver就不一样就出错了。
解决办法:随便改一个错误:就是要让外部文件的前面的值和里面配置文件取的值的名称相同,才能找到

<property name="driverClass" value="${jdbc.jdbcDriver}"></property>

三、spring中mybatis报错
错误报错信息:
Caused by: org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\eclipse\eclipse_new_new\web_new_new\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\testSSM_2020_12_04_Evening_classes\WEB-INF\classes\mybatis\mapper\UserMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [D:\eclipse\eclipse_new_new\web_new_new\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\testSSM_2020_12_04_Evening_classes\WEB-INF\classes\mybatis\mapper\UserMapper.xml]'. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'Blog'. Cause: java.lang.ClassNotFoundException: Cannot find class: Blog

Caused by: org.apache.ibatis.type.TypeException: Could not resolve type alias 'Blog'. Cause: java.lang.ClassNotFoundException: Cannot find class: Blog
错误原因:
这个错误是因为我写mapper.xml文件(我的是UserMapper.xml)的时候是直接copymybatis3中文文档https://mybatis.org/mybatis-3/zh/getting-started.html中的样例,然而我写的项目中又不一样

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.mybatis.example.BlogMapper">
  <select id="selectBlog" resultType="Blog">
    select * from Blog where id = #{id}
  </select>
</mapper>

解决办法:把那个无效的mapper.xml文件UserMapper.xml文件中的select方法注释掉或者去掉

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.feng.SSMTest.dao.userMapper">
  <!-- <select id="selectBlog" resultType="Blog">
    select * from Blog where id = #{id}
  </select> -->
</mapper>

四、把以上三个问题解决了终于运行成功了
在这里插入图片描述

SSM框架每一部分都是有联系的,哪里有一个问题都会影响全局。每一个小问题都是大问题。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值