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>
即可
SpringMVC Web项目升级为Springboot项目(二)的更多相关文章
- SpringMVC Web项目升级为Springboot项目(一)
一.项目改为Springboot项目 1.将pom中所有spring相关依赖删除,添加spring-boot-starter及spring-boot-starter-web(项目中可能有其他sprin ...
- 在同一个tomcat下部署多个springboot项目时,springboot项目无法正常启动的问题
这个问题是基于,不使用springboot内置的tomcat会产生(即使用自己的tomcat时). 今天在部署springboot项目的时候遇到了一个问题,怎么部署都访问不了,在网上查了很多原因,什么 ...
- maven项目改造成springboot项目
springboot项目其实归根到底就是一个maven项目,通常我们创建springboot项目,只要使用idea中的spring Initializr就可以创建就可以了. 今天我们来讲下如何改造一个 ...
- idea设置项目【非springboot项目】热部署
1.首先打开Edit Configurations 或者 2.添加的项目一定是war: exploded,而不是war 3.server这边,On 'Update' action选Redeploy,O ...
- springBoot 项目war包部署及改为war包后资源路径错误问题
参考资料: https://blog.csdn.net/rico_zhou/article/details/83415114 https://blog.csdn.net/pz641/article/d ...
- 从零开始的SpringBoot项目 ( 五 ) 整合 Swagger 实现在线API文档的功能
综合概述 spring-boot作为当前最为流行的Java web开发脚手架,越来越多的开发者选择用其来构建企业级的RESTFul API接口.这些接口不但会服务于传统的web端(b/s),也会服务于 ...
- 从零开始的SpringBoot项目 ( 四 ) 整合mybatis
一.创建一个SpringBoot项目 从零开始的SpringBoot项目 ( 二 ) 使用IDEA创建一个SpringBoot项目 二.引入相关依赖 <!--mysql数据库驱动--> & ...
- 使用 IDEA 创建 SpringBoot 项目(详细介绍)+ 源码案例实现
使用 IDEA 创建 SpringBoot 项目 一.SpringBoot 案例实现源码 二.SpringBoot 相关配置 1. 快速创建 SpringBoot 项目 1.1 新建项目 1.2 填写 ...
- 普通spring jsp+mybatis项目修改为springboot + jsp +mybatis项目
概述 由于公司决定使用spring cloud,但是公司积累了大量的普通的jsp项目,老的项目直接全部修改为springboot成本过高,周期比较长,而且公司业务正在快速拓展,所以需要把之前的老项目修 ...
随机推荐
- Python--可迭代对象,迭代器,生成器
记得在刚开始学Python的时候,看到可迭代对象(iterable).迭代器(iterator)和生成器(generator)这三个名词时,完全懵逼了,根本就不知道是啥意识.现在以自己的理解来详解下这 ...
- <?xml version="1.0" encoding="UTF-8"?> 的作用
version="1.0" 声明用的xml版本是1.0 encoding="UTF-8" 声明用xml传输数据的时候的字符编码,假如文档里面有中文,编码方式不是 ...
- django admin 修改批量操作内容
@admin.register(Template) class TemplateAdmin(admin.ModelAdmin): list_display = ( 'cn_title', 'start ...
- 关于CentOS
dd if=/dev/cdrom of=centos72.iso 自动挂载镜像: vi /etc/fstab /root/centos72.iso /mnt/cdrom iso9660 de ...
- Linux--奇思淫才
根据进程号找到可执行的文件路径 [ec2-user@baolin ~]$ ll /proc/<pid>/exe lrwxrwxrwx 1 ec2-user ec2-user 0 May 3 ...
- php获取两个时间戳之间相隔多少天多少小时多少分多少秒
/** * 返回两个时间的相距时间,*年*月*日*时*分*秒 * @param int $one_time 时间一 * @param int $two_time 时间二 * @param int $r ...
- Spark SQL大数据处理并写入Elasticsearch
SparkSQL(Spark用于处理结构化数据的模块) 通过SparkSQL导入的数据可以来自MySQL数据库.Json数据.Csv数据等,通过load这些数据可以对其做一系列计算 下面通过程序代码来 ...
- 同源策略jsonp和cors
同源策略: 同源策略(Same origin policy)是一种约定,它是浏览器最核心也最基本的安全功能,如果缺少了同源策略,则浏览器的正常功能可能都会受到影响.可以说Web是构建在同源策略基础之上 ...
- springboot的jar包
公用jar包放在api层.有些却包的不用增加pom文件.将已存在的jar包加入即可
- C#使用NanUI或ChromiumFx碰到的坑(一)
最近在花时间封装一个Razor模板+NanUI的Winform组件,发现了有个神奇地方,,由于需要使用CfxResourceHandler,用于把对cshtml文件的请求,编译成html并返回给CEF ...