gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 19:42:56 25 4
gpt4 key购买 nike

我正在使用 spring boot,我决定只是为了将我的项目拆分为模块。我有 4 个模块:Web、服务、存储库、域。除了JSP之外,一切正常,spring找不到这些页面。但是,当我没有将项目拆分为模块时,它就可以工作了。我没有更改配置。

这是我的网络模块结构

enter image description here

Runner 位于 web 模块中,这里是:

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

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

}

这是我的应用程序属性:

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

父 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>

和 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>

如果你能帮助我,我会很高兴)我再说一遍,当没有模块时它可以工作,不改变配置,只是添加模块它不起作用。

Result:

Response Screenshot

Intellij IDEA 还向我显示,即使我显式添加 View 解析器 bean,index.jsp 也没有 View 解析器

这是项目的github链接: https://github.com/DaimonCool/newsmanagementmultimodules

最佳答案

我发现了问题。我需要更改 intellij IDEA 中的工作目录。 Spring Boot 运行程序采用根路径,然后查找 jsp(在我的例子中它是父项目)。但我的运行器位于 Web 模块中,因此我需要 Spring Boot 运行器将根路径更改为 Web 模块(通过更改工作目录),而不是父级。

关于java - Spring Boot在多模块项目中找不到jsp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54646270/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com