首页 文章

Spring boot:不打开jsp文件

提问于
浏览
0

我正在开发简单的Spring Boot MVC应用程序 . 虽然我已经阅读了很多答案,所以我仍然无法修复Spring Boot没有找到我的.jsp文件 - 它显示whitelabel错误页面 .

项目结构:
Project structure.

  • 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

@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

public class ServletInitializer extends SpringBootServletInitializer {

        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(LearnBookApplication.class);
        }
    }
  • 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>
  • 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
  • 控制器
@Controller
public class ViewController {

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

}'

1 回答

相关问题