IDEA中Sprint MVC环境配置<mvc:default-servlet-handler/>报错

问题描述

在配置applicationContext.xml文件时,mvc:default-servlet-handler/出现问题不能正常使用,提示未声明。但是mvc其他的都可以正常使用,比如 mvc:annotation-driven/没有报错。


原因分析:

在网上查了可能的原因,第一种说spring 3的jar包就是没法用,可以换成spring4.0的jar包。我尝试了,没有用。第二种说,配置信息和用的spring jar包不是匹配的,我再换成了4.3.6jar包的基础上,改变了配置信息,mvc:default-servlet-handler/就没有报错了。

解决方案:

我的applicationContext.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:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-3.1.xsd
                        http://www.springframework.org/schema/mvc
                        http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<!--    自动创建并管理这个包以及这个包下的子包-->
    <context:component-scan base-package="com.jun.student"></context:component-scan>
<!--启用spring mvc的注解开发模式-->
    <mvc:annotation-driven/>
<!--    将图片/js/css等静态资源排除在外,可提高执行效率-->
    <mvc:default-servlet-handler/>
</beans>

更换spring jar包的过程:

  1. 下载spring jar包
    网址:https://repo.spring.io/ui/native/libs-release-local/org/springframework/spring/4.3.6.RELEASE/
    (我下了左边第一个)
  2. 解压下载好的,并打开lib文件夹,选择需要的jar包
    在这里插入图片描述
  3. 将需要的jar包贴到自己的项目的lib文件夹下
    路径如下:
    在这里插入图片描述

其他问题:不支持Java执行版本5

需要改两个地方
4. 打开setting
在这里插入图片描述
检查画圈的地方的版本号和自己这个项目用的的jdk是否一致,不一致改成这个项目用的
在这里插入图片描述

  1. 打开Project Structure
    在这里插入图片描述
    检查SDK版本
    在这里插入图片描述
    检查画圈地方是否和自己用的一致,报错不支持Java执行版本5很有可能这里选的是5那个选项
    在这里插入图片描述

  2. 全部改好重新运行就对啦

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值