博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringMVC Web项目升级为Springboot项目(二)
阅读量:4703 次
发布时间:2019-06-10

本文共 1813 字,大约阅读时间需要 6 分钟。

一、访问原项目地址,报404错误

由于原项目地址启动路径为http://localhost:8080/xxx

Spring boot默认启动路径为http://localhost:8080/

所以需要添加context-path配置,在application.properties中添加

server.servlet.context-path=/xxx/

即可

 

二、访问登录地址,报500错误

访问项目登录地址,报500错误,控制台中报错:

org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton.  This is an invalid application configuration.

此错误原因是未加载shiro配置文件

原项目shiro.xml配置文件在resource文件夹下,通过servlet.xml配置

由于springboot启动未加载servlet.xml中配置

所以只需要在Application类中添加

@ImportResource(locations={"classpath:shiro.xml"})

即可正确加载配置文件

 

三、程序启动后,访问页面无法正确加载css、img、js等静态资源

由于原先静态资源配置在spring-mvc.xml中

升级为springboot后,可将静态资源直接放入/resource/static/文件夹中

然后添加类MvcConfig,代码如下

package com.gauge.childheart;import org.springframework.context.annotation.Configuration;import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;@Configurationpublic class MvcConfig implements WebMvcConfigurer {    /*资源处理器*/    public void addResourceHandlers(ResourceHandlerRegistry registry) {        registry.addResourceHandler("/img/**").addResourceLocations("/static/img/");        registry.addResourceHandler("/assets/**").addResourceLocations("/static/assets/");        registry.addResourceHandler("/css/**").addResourceLocations("/static/css/");        registry.addResourceHandler("/js/**").addResourceLocations("/static/js/");    }}

即可正确加载静态资源文件

 

PS:如果生成时资源文件没有正确复制到生成目录,在pom中添加

src/main/resources
**/*.*

即可

转载于:https://www.cnblogs.com/punkrocker/p/10691310.html

你可能感兴趣的文章
C#垃圾回收机制
查看>>
31、任务三十一——表单联动
查看>>
python之hasattr、getattr和setattr函数
查看>>
maven使用阿里镜像配置文件
查看>>
Copy code from eclipse to word, save syntax.
查看>>
arguments.callee的作用及替换方案
查看>>
P2709 小B的询问
查看>>
PHP echo 和 print 语句
查看>>
第一讲 一个简单的Qt程序分析
查看>>
Centos 6.5下的OPENJDK卸载和SUN的JDK安装、环境变量配置
查看>>
poj 1979 Red and Black(dfs)
查看>>
【.Net基础03】HttpWebRequest模拟浏览器登陆
查看>>
zTree async 动态参数处理
查看>>
Oracle学习之常见错误整理
查看>>
数据库插入数据乱码问题
查看>>
altium annotate 选项设置 complete existing packages
查看>>
【模式识别与机器学习】——SVM举例
查看>>
【转】IT名企面试:微软笔试题(1)
查看>>
IO流入门-第十章-DataInputStream_DataOutputStream
查看>>
DRF的分页
查看>>