成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

springboot打包成war包的頁面如何存放

背景

十余年的西城網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。成都全網(wǎng)營銷推廣的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整西城建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。成都創(chuàng)新互聯(lián)公司從事“西城網(wǎng)站設(shè)計”,“西城網(wǎng)站推廣”以來,每個客戶項目都認(rèn)真落實執(zhí)行。

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

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

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

spring boot打包成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有很多限制。

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

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包

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ù)大家的。在此也非常感謝大家對創(chuàng)新互聯(lián)網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

網(wǎng)站欄目:springboot打包成war包的頁面如何存放
網(wǎng)站URL:http://jinyejixie.com/article20/pgidjo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器、服務(wù)器托管、微信公眾號商城網(wǎng)站、面包屑導(dǎo)航做網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設(shè)計
清流县| 澄城县| 黄大仙区| 兰西县| 乐都县| 阿荣旗| 秦安县| 彭阳县| 泸定县| 扶余县| 安仁县| 澎湖县| 道孚县| 温州市| 西林县| 四子王旗| 米林县| 姜堰市| 永福县| 兰溪市| 从江县| 滦平县| 东乡县| 蒙阴县| 水富县| 阜城县| 神池县| 南汇区| 启东市| 大同市| 民和| 海淀区| 汪清县| 花莲市| 综艺| 定边县| 思茅市| 宜昌市| 沈丘县| 古交市| 大竹县|