HTTP Status 500 - Servlet.init() for servlet springmvc threw exception 异常的解决方案

9 篇文章 0 订阅
6 篇文章 0 订阅

在这里插入图片描述
如图所示,这个异常网上很多答案说是jdk版本过高,但是不能解决问题,我的jsk15都没有问题;由此可见,不是jdk版本的问题

jdk都是向下兼容的,不存在版本过高问题

以下是我的解决访问:
问题:DispatcherServlet-servlet.xml 文件配置问题:

解决:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
		http://www.springframework.org/schema/beans/spring-beans-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/context
		http://www.springframework.org/schema/context/spring-context-3.2.xsd
		http://www.springframework.org/schema/aop
		http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
		http://www.springframework.org/schema/tx
		http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">


<!--1.配置一个url处理映射
    url的配置方式有三种: [通过访问的路径找到对应的控制器]
    2.BeanNameUrlHandlerMapping:找一个请求一个控制器处理  通过url的名字找到对应bean的name
    SimpleControllerHandlerAdapter:简单那的url处理映射 通过key找到bean的id控制器
    3.ControllerClassNameHandelMapper:[控制器的类名处理映射] 不用配置访问路径
        默认的访问路径就是类名 大写首字母变小写  加.do的后缀 userController.do
    -->
    <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"></bean>
    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="/user1.do">userController</prop>
                <prop key="/http.do">http</prop>
                <prop key="/user3.do">userController</prop>
            </props>
        </property>
    </bean>

    <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"></bean>

    <!--2.配置一个适配器处理适配器 :相当于配置了一个访问路径: 配置如何调用控制器的方法
    两种方式:SimpleControllerHandlerAdapter 动能:执行controller,调用controller里面的handleRequest方法
        返回mdeAndView
     第二种:httpRequstHandlerAdapter  负责调用httpRequestHandler
     -->
    <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"></bean>
    <bean class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter"></bean>

    <!--3.配置控制器-->
<!--    <bean name="/user.do" class="com.cwl.backoffice.web.controller.UserController"></bean>-->
    <!--3.相当于 name = /user.do
     id="userController"
     -->
    <bean id="userController" class="com.cwl.backoffice.web.controller.UserController"></bean>

    <bean name="/http.do" id="http" class="com.cwl.backoffice.web.controller.HttpController"></bean>
    <bean name="/useradd.do" class="com.cwl.backoffice.web.controller.UserAddController"></bean>

    <!--4.配置资源解析器-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!--前缀-->
        <property name="prefix" value="/WEB-INF/views"></property>
        <!--后缀-->
        <property name="suffix" value=".jsp"></property>
    </bean>
</beans>

没有配置id 或者是吧class写成了name,改过来就可以了;

<bean name="/http.do" id="http" class="com.cwl.backoffice.web.controller.HttpController"></bean

一定要搞清楚id name class的作用

id: 标识
name: 访问路径
class:资源路径

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值