IDEA project run SpringBoot + JSP, JSP pages can not access problem

Error as follows:

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
 
Thu Jan 18 11:01:36 CST 2018
There was an unexpected error (type=Not Found, status=404).
/WEB-INF/jsp/index.jsp

After collecting a lot of a lot of information online, I realized that the way to create a project with the idea about, suppose your code directory as follows:

learn-springboot
    |
    --- module1 (这是我们要运行的springboot+jsp项目)
    |
    --- module2

If you project the idea to create the learn-springboot this level, 

When you run module1 in IDEA, the C: \ Users \ \ Local \ under xxx \\ AppData Temp directory, generates two tomcat directory, as follows:

Which, tomcat.xxxx.port this directory does not automatically generate jsp java and class files.

But if the idea was built in a module1 this level,

When you run module1 in IDEA, the C: \ Users \ xxx \ AppData \ Local \ Temp under this directory will only generate tomcat.xxxx.port a directory, and when you visit in IE, in this path will generate corresponding jsp java class files and the corresponding jsp files can also be accessed, it will not be an exception, as follows:

In the eclipse run without exceptions, will only generate tomcat.xxx.port directory eclipse runtime and automatically generates jsp java and class files.

In fact, knowing this, we can already solve my problem. But for that matter, in the middle also found other solution, also summarized together here.

  1.  Module1 into the directory, use mvn spring-boot: Start run mode, the problem does not appear jsp files can not be found
  2.  In module1, add the following configuration class, jsp files can also solve the problem can not be found
@Configuration
public class TomcatConfig {
    @Bean
    public EmbeddedServletContainerFactory embeddedServletContainerFactory() {
        ConfigurableEmbeddedServletContainer factory = new TomcatEmbeddedServletContainerFactory();
        factory.setDocumentRoot(new File("D:\\Study\\learn-springboot\\module1\\src\\main\\webapp\\"));
        return (EmbeddedServletContainerFactory) factory;
    }
}

 

Guess you like

Origin blog.csdn.net/qq_42239765/article/details/91407191