简体   繁体   English

Spring Boot在多模块项目中找不到jsp

[英]Spring boot can't find jsp in multi modules project

I'm using spring boot and I decided just for example sake to split my project into modules. 我使用的是Spring Boot,例如,我决定将项目拆分为模块。 I have 4 modules, web, service, repository, domain. 我有4个模块,Web,服务,存储库,域。 All work okay except JSP, spring can't find these pages. 除了JSP之外,其他一切正常,spring无法找到这些页面。 But when I didn't split my project to modules it worked. 但是,当我没有将项目拆分为模块时,它就可以工作。 I didn't change configuration. 我没有更改配置。

This is my structure of web module 这是我的网络模块结构

在此处输入图片说明

Runner is located in web module, Here it is: Runner位于Web模块中,这里是:

@SpringBootApplication(scanBasePackages = "kz.epam.javalab.daimoncool")
public class WebApplication {

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

}

This is my application.properties: 这是我的application.properties:

spring.mvc.throw-exception-if-no-handler-found=true
spring.resources.add-mappings=false

spring.mvc.view.prefix:/WEB-INF/jsp/
spring.mvc.view.suffix:.jsp

spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true

spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:orcl
spring.datasource.username=
spring.datasource.password=
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
spring.jpa.properties.hibernate.physical_naming_strategy=com.vladmihalcea.hibernate.type.util.CamelCaseToSnakeCaseNamingStrategy

spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=
spring.mail.password=
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.ssl.trust=smtp.gmail.com

Parent POM xml: 父POM xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>kz.epam.javalab.daimoncool</groupId>
    <artifactId>newsmanagementparent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>newsmanagementparent</name>
    <packaging>pom</packaging>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <modules>
        <module>repository</module>
        <module>service</module>
        <module>web</module>
        <module>domain</module>
    </modules>

    <properties>
        <java.version>1.8</java.version>
        <module-version>0.0.1-SNAPSHOT</module-version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.20</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.5</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.25</version>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>2.4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.spockframework</groupId>
            <artifactId>spock-core</artifactId>
            <version>1.1-groovy-2.4</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>kz.epam.javalab.daimoncool</groupId>
                <artifactId>web</artifactId>
                <version>${module-version}</version>
            </dependency>
            <dependency>
                <groupId>kz.epam.javalab.daimoncool</groupId>
                <artifactId>service</artifactId>
                <version>${module-version}</version>
            </dependency>
            <dependency>
                <groupId>kz.epam.javalab.daimoncool</groupId>
                <artifactId>domain</artifactId>
                <version>${module-version}</version>
            </dependency>
            <dependency>
                <groupId>kz.epam.javalab.daimoncool</groupId>
                <artifactId>repository</artifactId>
                <version>${module-version}</version>
            </dependency>

        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.codehaus.gmavenplus</groupId>
                <artifactId>gmavenplus-plugin</artifactId>
                <version>1.5</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

And web POm xml: 和Web POm xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>kz.epam.javalab.daimoncool</groupId>
    <artifactId>web</artifactId>
    <packaging>war</packaging>

    <parent>
        <groupId>kz.epam.javalab.daimoncool</groupId>
        <artifactId>newsmanagementparent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>kz.epam.javalab.daimoncool</groupId>
            <artifactId>domain</artifactId>
        </dependency>

        <dependency>
            <groupId>kz.epam.javalab.daimoncool</groupId>
            <artifactId>service</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.5</version>
        </dependency>

        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.4</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <!-- Need this to compile JSP -->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>
        <!-- Need this to compile JSP -->
        <dependency>
            <groupId>org.eclipse.jdt.core.compiler</groupId>
            <artifactId>ecj</artifactId>
            <version>4.6.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

I would be happy if you can help me) And I repeat, that it works when there were no modules, without changing the configuration, just adding modules it doesn't work. 如果您能帮助我,我将非常高兴。)我再说一遍,它在没有模块的情况下仍然有效,而无需更改配置,只是添加模块是行不通的。

Result: 结果:

响应截图

Also Intellij IDEA shows me that there is not view resolver for index.jsp, even though I add view resolver bean explicitly 另外,Intellij IDEA告诉我,即使我显式添加了视图解析器bean,也没有index.jsp的视图解析器。

Here is github link of project: https://github.com/DaimonCool/newsmanagementmultimodules 这是项目的github链接: https : //github.com/DaimonCool/newsmanagementmultimodules

I found the problem. 我发现了问题。 I needed to change the working directory in intellij IDEA. 我需要在intellij IDEA中更改工作目录。 Spring boot runner takes root path and then look for the jsp (in my case it was the parent project). Spring BootRunner使用根路径,然后查找jsp(在我的情况下,它是父项目)。 But my runner was in web module, so I needed spring boot runner to change root path to web module (by changing the working directory), not to parent. 但是我的跑步者在Web模块中,所以我需要Spring Boot跑步者将根路径更改为Web模块(通过更改工作目录),而不是父目录。

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

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