SpringMVC Web项目升级为Springboot项目(二)

一、访问原项目地址,报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;

@Configuration
public 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中添加

<build>   
<resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.*</include>
                </includes>
            </resource>
        </resources>
    </build>

即可

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值