scenario

When using the spring Boot + HTML or JSP combination, the directory is as follows

Setting the view code

@Configuration @EnableWebMvc public class MvcConfiguration implements WebMvcConfigurer, ApplicationContextAware { @Override public void configureViewResolvers(ViewResolverRegistry registry) { InternalResourceViewResolver resolver = new InternalResourceViewResolver(); resolver.setPrefix("/WEB-INF/html/"); resolver.setSuffix(".html"); registry.viewResolver(resolver); }}Copy the code

After unpacking the JAR package, I found that all the files in webApp were not packed in the jar package. I searched a lot of information. Either I specified the packaged plug-in of Spring Boot, or I unpacked the files in WebApp first and put them in the jar package. But it’s okay to unzip it and put it in, but it’s too much trouble.

Take a moment to think about why webApp files are not packaged inside

Follow the packaging, outside in the site search to a blog, found a magical thing, is the spring boot + JSP, can be directly into a war file, and then directly Java – jar XXX. War can, at the same time the JPS | HTML file will also be in, It wouldn’t happen that the files wouldn’t be found,

Packaged in the war of the unzipped directory structure is as follows, have one more WEB – INF, if you specify the jar, then the WEB – INF will not be packaged in a jar, so a less, so use the jar to perform error will be 404,

Specify Packaging in the POM file

Java-jar O2O. War

If you want war to run in Tomcat, add the following code to the startup class:

The original blog: htr3n. Making. IO / 2018/12 / JSP…

Pay attention to

There is no need to change the version of the Spring-boot-Maven-plugin to 1.4.2 or so. This is not the case, as long as the view is configured and the project structure is correct, you can simply package it as a WAR and run it.