简体   繁体   English

春季启动:不会打开jsp文件

[英]Spring boot: Doesn't open jsp files

I'm developing simple Spring Boot MVC application. 我正在开发简单的Spring Boot MVC应用程序。 Althought I have read many answers on SO I still can't fix Spring Boot not finding my .jsp files - it displays whitelabel error page. 虽然我已经阅读了很多关于SO的答案,但是我仍然无法修复Spring Boot找不到我的.jsp文件-它显示whitelabel错误页面。

Project Structure: 项目结构: 项目结构。

  1. pom.xml 的pom.xml

      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.learnbook</groupId> <artifactId>learnbook</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>LearnBook</name> <description>We want to make the best courses in the market </description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.3.RELEASE</version> </parent> <dependencies> <!-- https://mvnrepository.com/artifact/javax.servlet/jstl --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>org.hibernate.common</groupId> <artifactId>hibernate-commons-annotations</artifactId> <version>4.0.4.Final</version> </dependency> <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>4.3.10.Final</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>4.3.11.Final</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-taglibs</artifactId> </dependency> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.3.1</version> </dependency> <!-- Apache Commons Upload --> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.4</version> </dependency> <dependency> <groupId>com.cloudinary</groupId> <artifactId>cloudinary-http44</artifactId> <version>1.4.6</version> </dependency> <dependency> <groupId>com.cloudinary</groupId> <artifactId>cloudinary-taglib</artifactId> <version>1.4.6</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> <properties> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.source>1.8</maven.compiler.source> <java.version>1.8</java.version> </properties> </project> 

2.LearnBookApplication.java 2.LearnBookApplication.java

    @EnableJpaRepositories(basePackages = "net.learnbook.repository")
    @SpringBootApplication
    public class LearnBookApplication {

        public static void main(String[] args) {
            SpringApplication.run(LearnBookApplication.class, args);
        }

        @Bean
        @ConfigurationProperties(prefix = "datasource.main")
        public DataSource siteDataSourceBean() {
            return DataSourceBuilder.create().build();
        }

        @Bean
        public LocalContainerEntityManagerFactoryBean siteEntityManagerFactoryBean(EntityManagerFactoryBuilder builder) {
            return builder.dataSource(siteDataSourceBean()).packages("net.learnbook.model").persistenceUnit("learnbookPU")
                    .build();
        }

    }

3.ServletInitializer.java 3.ServletInitializer.java

    public class ServletInitializer extends SpringBootServletInitializer {

        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(LearnBookApplication.class);
        }
    }
  1. web.xml web.xml中

     <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <display-name>learnbook</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app> 
  2. application.properties application.properties

     spring.mvc.view.prefix=/WEB-INF/views/ spring.mvc.view.suffix=.jsp security.basic.enabled=false datasource.main.url: jdbc:mysql://localhost/learnbook?autoReconnect=true&useSSL=false datasource.main.username:root datasource.main.password:root datasource.main.driverClassName:com.mysql.jdbc.Driver spring.jpa.generate-ddl=true spring.jpa.hibernate.ddl-auto:create-drop spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect spring.jpa.show-sql=true 
  3. Controller 调节器

     @Controller public class ViewController { @RequestMapping(value = "/", method = { RequestMethod.GET,RequestMethod.POST}, name = "home_index") public String index() { return "index"; } }' 

FYI FYI

From Spring boot Documentation: 从Spring Boot文档中:

JSPs should be avoided if possible, there are several known limitations when using them with embedded servlet containers. 如果可能,应避免使用JSP,将它们与嵌入式Servlet容器一起使用时存在一些已知的限制。 You can take further reading here: 您可以在这里进一步阅读:

http://docs.spring.io/spring-boot/docs/1.5.3.RELEASE/reference/htmlsingle/#boot-features-spring-mvc-template-engines http://docs.spring.io/spring-boot/docs/1.5.3.RELEASE/reference/htmlsingle/#boot-features-spring-mvc-template-engines

I believe that this means if you still want to use JSP pages, then you'll have to get rid of the embedded tomcat. 我相信这意味着,如果您仍然想使用JSP页面,则必须摆脱嵌入式的tomcat。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM