springboot 启动类启动跳转到前端网页404问题的两个解决方案
前段时间研究springboot
发现使用Application类启动的话, 可以进入Controller方法并且返回数据,但是不能跳转到WEB-INF目录下网页,
前置配置
server:
port: 8086
tomcat:
uri-encoding: UTF-8
servlet:
context-path: /
spring:
mvc:
view:
suffix: .jsp
prefix: /WEB-INF/views/
view:
suffix: .jsp
prefix: /WEB-INF/views/

使用启动类或者启动后。jar 404错误

控制台可以看见已经进入方法了

解决方案1: 使用spring-boot:run 启动

会导致问题:
打包成jar包 使用java -jar springboot.jar, 访问前端 一样会404
缺陷弥补方案 ,打包成 war包, 使用java -jar springboot.war 就OK了

解决方案2:配置pom.xml ,请看红色字体,
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.yml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.yml</include>
<include>**/*.txt</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/webapp</directory>
<targetPath>META-INF/resources</targetPath>
<includes>
<include>**/**</include>
</includes>
</resource>
</resources>
</build>
<resource>
<directory>src/main/webapp</directory>
<targetPath>META-INF/resources</targetPath>
<includes>
<include>**/**</include>
</includes>
</resource>
进行webapp目录配置后,
使用启动类启动 和 打包成jar包 都可以正常访问了
O(∩_∩)O哈哈~
修改了配置 记得 clean 一下哦
原文地址 https://blog.csdn.net/q18771811872/article/details/88051260
springboot 启动类启动跳转到前端网页404问题的两个解决方案的更多相关文章
- springBoot项目启动类启动无法访问
springBoot项目启动类启动无法访问. 网上也查了一些资料,我这里总结.下不来虚的,也不废话. 解决办法: 1.若是maven项目,则找到右边Maven Projects --->Plug ...
- SpringBoot测试类启动错误 java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
报错 java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @Cont ...
- 【spring boot】启动类启动 错误: 找不到或无法加载主类 com.codingapi.tm.TxManagerApplication 的解决方案
导入的一个外部的spring boot项目,运行启动类,出现错误:找不到或无法加载主类 com.codingapi.tm.TxManagerApplication 解决方案: 将所有错误处理完成后,再 ...
- SpringBoot无法书写主启动类的情况之一
首先需要引入 spring-boot-starter-web 依赖[springboot web 项目 启动器 jar包]: 如果使用镜像请确保镜像路径正确,可参看笔者博客园m-yb的maven 安装 ...
- SpringBoot源码分析之---SpringBoot项目启动类SpringApplication浅析
源码版本说明 本文源码采用版本为SpringBoot 2.1.0BUILD,对应的SpringFramework 5.1.0.RC1 注意:本文只是从整体上梳理流程,不做具体深入分析 SpringBo ...
- springboot 单元测试 指定启动类
问题 在做单元测试时,写了一个工具类,用于注入spring的上下文. public class AppBeanUtil implements ApplicationContextAware { pri ...
- springboot系列(三) 启动类中关键注解作用解析
一.Springboot:请求入口 @SpringBootApplication @EnableAspectJAutoProxy @EnableScheduling @EnableTransactio ...
- 【杂谈】SpringBoot为啥不用配置启动类
前言 在学习SparkJava.Vert.x等轻量级Web框架的时候,都遇到过打包问题,这两个框架打包的时候都需要添加额外的Maven配置,并指定启动类才能得到可执行的JAR包: 而springboo ...
- 震惊!你还不知道SpringBoot真正的启动引导类
引言 SpringBoot项目中的启动类,一般都是XXApplication,例如「StatsApplication」,「UnionApplication」. 每个项目的启动类名称都不一样.但是它的启 ...
随机推荐
- freertos知识点笔记——队列、二值信号量、计数信号量
队列1.队列queue通常用于任务之间的通信,一个任务写缓存,另一个任务读缓存.队列还会有等待时间,2.阻塞超时时间.如果在发送时队列已满,这个时间即是任务处于阻塞态等待队列空间有效的最长等待时间.如 ...
- 二叉苹果树——树形Dp(由根到左右子树的转移)
题意:给出一个二叉树,每条边上有一定的边权,并且剪掉一些树枝,求留下 Q 条树枝的最大边权和. ( 节点数 n ≤100,留下的枝条树 Q ≤ n ,所有边权和 ∑w[i] ≤30000 ) 细节:对 ...
- BZOJ 4027: [HEOI2015]兔子与樱花
贪心 #include<cstdio> #include<algorithm> using namespace std; int cnt,n,m,F[2000005],c[20 ...
- CodeForces 567F DP Mausoleum
本着只贴代码不写分析的题解是在耍流氓的原则,还是决定写点分析. 思路很清晰,参考的官方题解,一下文字仅对题解做一个简要翻译. 题意: 有1~n这n个数,每个数用两次.构成一个长为2n的序列,而且要求序 ...
- MongoDB学习-->Gridfs分布式存储&DBRef关联查询
mongodb自带的一个分布式文件系统 fs.files _id filename md5 size uploaddate contenttype metadata {"user_id&qu ...
- [转] Vuex入门(2)—— state,mapState,...mapState对象展开符详解
1.state state是什么? 定义:state(vuex) ≍ data (vue) vuex的state和vue的data有很多相似之处,都是用于存储一些数据,或者说状态值.这些值都将被挂载 ...
- edge浏览器识别ip地址为手机号的解决办法
edge浏览器识别ip地址为手机号的解决办法 今天突然发现类似101.231.70.242的ip地址会在edge浏览器里面识别为可点击的链接,后来看了一下,原因就是被识别为手机号了,因为我发现点击的时 ...
- luogu3808 luogu3796 AC自动机(简单版) AC自动机(加强版)
纪念一下我一晚上写了八遍AC自动机 这是加强版的: #include <iostream> #include <cstring> #include <cstdio> ...
- 深入了解ASO
ASO对于一些人来说可能很陌生,很多人都听说过SEO,没有听说过ASO(我也是最近才知道这个领域),因为这是一个数字营销的一个新领域.ASO(App Store Optimization)是为了让自己 ...
- Could not load file or assembly 'AjaxControlToolkit' or one of its dependencies
Could not load file or assembly 'AjaxControlToolkit' or one of its dependencies. API 调用退出异常. (Except ...