springboot訪問jsp頁面404

結論

在springboot1.4.2之前的版本,將項目打包成jar,添加上對應的依賴,不會出現404的問題,在1.4.2之後,如果將項目打包成jar,永遠都是404,因爲從1.4.2之後,spring不在支持jar包形式訪問jsp頁面,如果想解決,只能將jar改爲war形式

1.4.2之前,jar文件正確配置

		#必須
		<dependency>
			<groupId>org.apache.tomcat.embed</groupId>
			<artifactId>tomcat-embed-jasper</artifactId>
			<scope>provided</scope>
		</dependency>
		#必須
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jstl</artifactId>
		</dependency>
		<build>
		<finalName>xxx</finalName>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					#打包指明主類,不然會報錯
					<mainClass>com.WithjoyApplication</mainClass>
				</configuration>
				#用1.4.1版本
				<version>1.4.1.RELEASE</version>
			</plugin>
		</plugins>
		#可選,如果按上面配置不可以,架上這個配置
		<resources>
			<resource>
				<directory>src/main/webapp</directory>
				<targetPath>META-INF/resources</targetPath>
				<includes>
					<include>**/**</include>
				</includes>
			</resource>
			<resource>
				<directory>src/main/resources</directory>
				<filtering>true</filtering>
			</resource>
		</resources>
	</build>

1.4.2之後,只能用war包形式支持jsp頁面

傳送門stackOverFlow
傳送門韓國人也遇見404的問題了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章