2020/5/29日記錄
springboot項目寫了一個小jsp,一個請求映射,jsp裡面就放一張圖檔,本地可以正常通路。
controller端代碼
@Controller
public class DemoController {
private static final Logger logger = LoggerFactory.getLogger(DemoController.class);
@RequestMapping("/hello")
public String index() {
logger.info("進入hello接口");
return "/test";
}
}
jsp代碼
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>XX網歡迎您</title>
</head>
<body>
<img src="images/test.png"></img>
</body>
</html>
本地運作全部ok沒問題可以直接通路
但是,但是,但是!
部署到linux後卻是404錯誤,其他接口均正常,就是通路不到頁面!
(桌子hp-10)
(桌子hp-10)
怎麼辦呢,百度吧。
首先反編譯之後發現,項目中沒有WEB-INF檔案夾
于是加入resource插件打包
<resources>
<resource>
<!-- 指定resources插件處理哪個目錄下的資源檔案 -->
<directory>src/main/webapp</directory>
<!--注意此次必須要放在此目錄下才能被通路到 -->
<targetPath>META-INF/resources</targetPath>
<includes>
<include>**/**</include>
</includes>
<filtering>false</filtering>
</resource>
<!-- 将項目中的配置檔案,打包至classes下面 -->
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
再試試,還是不404
繼續找問題。
(桌子hp-10)
沒有指定jdk版本,于是加入了
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
還是404。我是程式員,我脾氣很好!脾氣很好!氣很好!很好!好!
(桌子hp-10)
(發量-10)
最後,終于給我逮到尾巴了
springboot的打包隻有1.4.2.RELEASE可以通路到jsp!!!
于是加入
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.4.2.RELEASE</version>
<!-- 支援調試 -->
<configuration>
<fork>true</fork>
</configuration>
</plugin>
再部署到linux上,就正常了
(桌子hp-10)
(桌子hp-10)
(桌子hp-10)
(嗷嗚~~)