欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

spring boot打包成war包的頁面如何存放

 更新時間:2019年11月12日 11:31:10   作者:一天不進(jìn)步,就是退步  
這篇文章主要介紹了spring boot打包成war包的頁面該放到哪里,很多朋友對這個問題都很疑惑,今天小編給大家分享一篇教程,需要的朋友可以參考下

背景

經(jīng)常有朋友問我,平時都是使用spring mvc,打包成war包發(fā)布到tomcat上,如何快速到切換到spring boot的war或者jar包上?

先來看看傳統(tǒng)的war包樣式是什么樣子的?

1. 傳統(tǒng)的spring MVC格式的war包

可以看到,webapp/resouces文件存放css/js/html等靜態(tài)文件,WEB-INF存放jsp動態(tài)文件。

對應(yīng)的配置文件

@EnableWebMvc //mvc:annotation-driven
@Configuration
@ComponentScan({ "com.xxx.web" })
public class SpringWebConfig extends WebMvcConfigurerAdapter {
 
 @Override
 public void addResourceHandlers(ResourceHandlerRegistry registry) {
  registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
 }
 
 @Bean
 public InternalResourceViewResolver viewResolver() {
  InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
  viewResolver.setViewClass(JstlView.class);
  viewResolver.setPrefix("/WEB-INF/views/jsp/");
  viewResolver.setSuffix(".jsp");
  return viewResolver;
 }
 
}

對應(yīng)xml的配置如下:

<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:mvc="http://www.springframework.org/schema/mvc"
 xsi:schemaLocation="
  http://www.springframework.org/schema/beans  
  http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/mvc 
  http://www.springframework.org/schema/mvc/spring-mvc.xsd
  http://www.springframework.org/schema/context 
  http://www.springframework.org/schema/context/spring-context.xsd ">
 
 <context:component-scan base-package="com.xxxx.web" />
 
 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
  <property name="prefix" value="/WEB-INF/views/jsp/" />
  <property name="suffix" value=".jsp" />
 </bean>
 
 <mvc:resources mapping="/resources/**" location="/resources/" />
  
 <mvc:annotation-driven />
 
</beans>

2.spring boot格式的jar包

jar的結(jié)構(gòu),spring 盡量避免jsp的動態(tài)文件,而是使用如Thymeleaf 、FreeMarker等模板引擎,因為jsp有很多限制。

28.4.5 JSP Limitations

When running a Spring Boot application that uses an embedded servlet container (and is packaged as an executable archive), there are some limitations in the JSP support.

With Jetty and Tomcat, it should work if you use war packaging. An executable war will work when launched with java -jar, and will also be deployable to any standard container. JSPs are not supported when using an executable jar.

Undertow does not support JSPs.

Creating a custom error.jsp page does not override the default view for error handling. Custom error pages should be used instead.

3.spring boot 格式的war包

如何切換?

其實,通過上面的結(jié)構(gòu),我們可以看出,spring boot的標(biāo)準(zhǔn)規(guī)格還是不建議使用jsp的,推薦使用Thymeleaf 、FreeMarker等模板引擎,然后所有的靜態(tài)文件同樣存儲在resources下面,可以使用代碼配置動態(tài)代碼

@Configuration
@EnableWebMvc
public class SpringConfig
{
 @Bean
 public InternalResourceViewResolver viewResolver()
 {
  InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
  viewResolver.setPrefix("/WEB-INF/view/");
  viewResolver.setSuffix(".jsp");
  
  return viewResolver;
 }
}

或者靜態(tài)屬性配置

spring.mvc.static-path-pattern=/resources/**

來自定義配置。

也可以使用靜態(tài)文件動態(tài)化

spring.resources.chain.strategy.content.enabled=true
spring.resources.chain.strategy.content.paths=/**
spring.resources.chain.strategy.fixed.enabled=true
spring.resources.chain.strategy.fixed.paths=/js/lib/
spring.resources.chain.strategy.fixed.version=v12

注意:centos下使用tomcat時,編譯的jsp文件,上傳的文件等等默認(rèn)都存儲在臨時目錄里,會

If you choose to use Tomcat on centos, be aware that, by default, a temporary directory is used to store compiled JSPs, file uploads, and so on. This directory may be deleted by tmpwatch while your application is running, leading to failures. To avoid this behavior, you may want to customize your tmpwatch configuration such that tomcat.* directories are not deleted or configure server.tomcat.basedir such that embedded Tomcat uses a different location.

總結(jié)

以上所述是小編給大家介紹的spring boot打包成war包的頁面如何存放,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

相關(guān)文章

  • MyBatis中防止SQL注入講解

    MyBatis中防止SQL注入講解

    這篇文章主要介紹了MyBatis中防止SQL注入,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2021-12-12
  • java創(chuàng)建excel示例(jxl使用方法)

    java創(chuàng)建excel示例(jxl使用方法)

    Java Excel是一開放源碼項目,通過它Java開發(fā)人員可以讀取Excel文件的內(nèi)容、創(chuàng)建新的Excel文件、更新 已經(jīng)存在的Excel文件。下面是使用方法,包括去掉網(wǎng)格線、字體設(shè)置、單元格設(shè)置、對齊方式等設(shè)置
    2014-03-03
  • Spring?data?jpa緩存機(jī)制使用總結(jié)

    Spring?data?jpa緩存機(jī)制使用總結(jié)

    這篇文章主要介紹了Spring?data?jpa緩存機(jī)制使用總結(jié),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-12-12
  • 如何使用stream從List對象中獲取某列數(shù)據(jù)

    如何使用stream從List對象中獲取某列數(shù)據(jù)

    這篇文章主要介紹了如何使用stream從List對象中獲取某列數(shù)據(jù)問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • java jdbc連接和使用詳細(xì)介紹

    java jdbc連接和使用詳細(xì)介紹

    這篇文章主要介紹了 java jdbc連接和使用詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下
    2016-12-12
  • SpringCloud微服務(wù)調(diào)用丟失請求頭的問題及解決方案

    SpringCloud微服務(wù)調(diào)用丟失請求頭的問題及解決方案

    在Spring Cloud 中微服務(wù)之間的調(diào)用會用到Feign,但是在默認(rèn)情況下,Feign 調(diào)用遠(yuǎn)程服務(wù)存在Header請求頭丟失問題,下面給大家分享SpringCloud微服務(wù)調(diào)用丟失請求頭的問題及解決方案,感興趣的朋友一起看看吧
    2024-02-02
  • 關(guān)于SpringBoot微服務(wù)發(fā)布與部署的三種方式

    關(guān)于SpringBoot微服務(wù)發(fā)布與部署的三種方式

    SpringBoot 框架只提供了一套基于可執(zhí)行 jar 包(executable jar)格式的標(biāo)準(zhǔn)發(fā)布形式,但并沒有對部署做過多的界定,而且為了簡化可執(zhí)行 jar 包的生成,SpringBoot 提供了相應(yīng)的 Maven 項目插件,需要的朋友可以參考下
    2023-05-05
  • java網(wǎng)上圖書商城(9)支付模塊

    java網(wǎng)上圖書商城(9)支付模塊

    這篇文章主要為大家詳細(xì)介紹了java網(wǎng)上圖書商城,支付模塊,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • 如何用java程序(JSch)運行遠(yuǎn)程linux主機(jī)上的shell腳本

    如何用java程序(JSch)運行遠(yuǎn)程linux主機(jī)上的shell腳本

    這篇文章主要介紹了如何用java程序(JSch)運行遠(yuǎn)程linux主機(jī)上的shell腳本,幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-08-08
  • java后臺接受到圖片后保存方法

    java后臺接受到圖片后保存方法

    在本篇文章里小編給大家整理了關(guān)于java后臺接受到圖片后怎么保存的相關(guān)知識點,需要的朋友們參考學(xué)習(xí)下。
    2019-06-06

最新評論