springboot打包成war包的页面该如何存放-创新互联
今天就跟大家聊聊有关springboot打包成war包的页面该如何存放,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
为武鸣等地区用户提供了全套网页设计制作服务,及武鸣网站建设行业解决方案。主营业务为网站设计制作、网站设计、武鸣网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!背景
经常有朋友问我,平时都是使用spring mvc,打包成war包发布到tomcat上,如何快速到切换到spring boot的war或者jar包上?
先来看看传统的war包样式是什么样子的?
1. 传统的spring MVC格式的war包
可以看到,webapp/resouces文件存放css/js/html等静态文件,WEB-INF存放jsp动态文件。
对应的配置文件
@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; } }
对应xml的配置如下:
2.spring boot格式的jar包
jar的结构,spring 尽量避免jsp的动态文件,而是使用如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包
如何切换?
其实,通过上面的结构,我们可以看出,spring boot的标准规格还是不建议使用jsp的,推荐使用Thymeleaf 、FreeMarker等模板引擎,然后所有的静态文件同样存储在resources下面,可以使用代码配置动态代码
@Configuration@EnableWebMvcpublic class SpringConfig{ @Bean public InternalResourceViewResolver viewResolver() { InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); viewResolver.setPrefix("/WEB-INF/view/"); viewResolver.setSuffix(".jsp"); return viewResolver; }}
或者静态属性配置
spring.mvc.static-path-pattern=/resources/**
来自定义配置。
也可以使用静态文件动态化
spring.resources.chain.strategy.content.enabled=truespring.resources.chain.strategy.content.paths=/**spring.resources.chain.strategy.fixed.enabled=truespring.resources.chain.strategy.fixed.paths=/js/lib/spring.resources.chain.strategy.fixed.version=v12
注意:centos下使用tomcat时,编译的jsp文件,上传的文件等等默认都存储在临时目录里,会
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.
看完上述内容,你们对springboot打包成war包的页面该如何存放有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。
网站标题:springboot打包成war包的页面该如何存放-创新互联
分享路径:http://azwzsj.com/article/cogcho.html