spring boot server deployment jar package jsp resource 404

Description of the problem : The jar package of the project is deployed to the server, and it can be logged in and accessed normally, but the jsp page reports 404. After testing, it is found that there are many things, such as relying on the jar package and static resource jsp files. After SpringBoot embeds the Tomcat server to start the project by default, there are interfaces that can be accessed normally, but only JSP pages cannot be accessed.
Below is my packaging dependencies (correct)

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>1.4.2.RELEASE</version>
                <configuration>
                    <mainClass>ccom.opao.re.MainApplication</mainClass>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <!-- 过滤后缀为pkcs12、jks的证书文件 -->
                    <nonFilteredFileExtensions>
                        <nonFilteredFileExtension>keystore</nonFilteredFileExtension>
                    </nonFilteredFileExtensions>
                </configuration>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/**</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/webapp</directory>
                <includes>
                    <include>**/**</include>
                </includes>
                <targetPath>META-INF/resources</targetPath>
            </resource>
        </resources>
    </build>

Special attention should be paid here to the version of spring-boot-maven-plugin. It seems that other versions of 1.4.2 will not work, and the version of 1.4.2 must add the path of the startup class, otherwise an error will be reported and the corresponding spring-boot version must be <mainClass>ccom.opao.re.MainApplication</mainClass>
changed Unable to find a single main class from the following candidates
. After the deployment of Cheng 1.4.2
is completed, wait for the dependent package to be imported, repackage and release it!

Supplement : static resource filtering

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Component
public class WebConfig implements WebMvcConfigurer {
    
    
    /*
     * 添加静态资源文件,外部可以直接访问地址
     *
     * @param registry
     */

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
    
    
        registry.addResourceHandler("/static/").addResourceLocations("classpath:/static/index.html");
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }
}

Guess you like

Origin blog.csdn.net/Your1221/article/details/119911305