我一直在努力解决这个问题,但没有取得太大的成功,所以任何暗示解决方案的线索都将不胜感激。我根本不是 Maven 专家,所以这可能是主要问题。
我目前有一个 SpringBoot 后端,如果我从 Intellij SpringBoot 运行它,它可以完美运行。但是如果我 mvn clean install 创建一个 war 包部署在 Tomcat8.5 然后我得到一个 404 错误 我所有的路线尝试过。
这是父目录的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>eu.sacs</groupId>
<artifactId>sacs-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
<description>Parent</description>
<modules>
<module>sacs-knowledge-extraction</module>
<module>sacs-repository-oracle</module>
<module>sacs-service</module>
<module>sacs-webservice</module>
</modules>
<prerequisites>
<maven>3</maven>
</prerequisites>
<properties>
<framework.version>0.0.0</framework.version>
<java.version>1.10</java.version>
<repo.path></repo.path>
</properties>
<dependencyManagement>
<dependencies>
<!-- Module dependencies -->
<dependency>
<groupId>eu.sacs</groupId>
<artifactId>sacs-webservice</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>eu.sacs</groupId>
<artifactId>sacs-service</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>eu.sacs</groupId>
<artifactId>sacs-repository-oracle</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>eu.sacs</groupId>
<artifactId>sacs-knowledge-extraction</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Spring dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- JSON -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.1.2</version>
</dependency>
<!-- Apache Jena -->
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-core</artifactId>
<version>3.2.0</version>
</dependency>
<!-- Apache POI -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.15</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.15</version>
</dependency>
<!-- Database - Oracle -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.6.0</version>
</dependency>
<!-- Apache Commons DBCP -->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.1.0</version>
<scope>test</scope>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-cas</artifactId>
<version>5.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>5.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>5.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>5.1.0.RELEASE</version>
</dependency>
<!-- Excel -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.0.0</version>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>sacs</id>
<url>file://${repo.path}</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>sacs</id>
<url>file://${repo.path}</url>
</pluginRepository>
</pluginRepositories>
<build>
<!-- <finalName>${warname}</finalName> -->
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.5.RELEASE</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<outputDirectory>.</outputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.10</source>
<target>1.10</target>
</configuration>
</plugin>
</plugins>
</build>
而这个是webservice的(其他的模块都编译成jar,用于webservice)
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>eu.sacs</groupId>
<artifactId>sacs-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>sacs-webservice</artifactId>
<packaging>war</packaging>
<name>${project.artifactId}</name>
<description>Rest API and Controller</description>
<dependencies>
<dependency>
<groupId>eu.sacs</groupId>
<artifactId>sacs-service</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-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-cas</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</dependency>
</dependencies>
最后是 Tomcat 日志的相关部分:
25-Oct-2018 12:58:15.012 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [C:\apache-tomcat-8.5.34\webapps\sacs-webservice-1.0-SNAPSHOT.war]
25-Oct-2018 12:58:23.167 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
25-Oct-2018 12:58:23.636 WARNING [localhost-startStop-1] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [216] milliseconds.
25-Oct-2018 12:58:23.677 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [C:\apache-tomcat-8.5.34\webapps\sacs-webservice-1.0-SNAPSHOT.war] has finished in [8,665] ms
最佳答案
部署期间没有错误sacs-webservice-1.0-SNAPSHOT.war
在你的日志中。默认情况下,WAR 名称是部署后的上下文路径,因此在您的情况下,示例 URL 将类似于 http://localhost:8080/sacs-webservice-1.0-SNAPSHOT/index.html
.
当从 IntelliJ 中运行时,WAR 文件名不是上下文路径的一部分,因此示例 URL 看起来像 http://localhost:8080/index.html
.这将进一步取决于 IntelliJ 中的运行配置,但通常适用于 mvn clean package spring-boot:run
。命令。
底线是,URL 不同,因为您选择使用独立的 Tomcat。
关于java - Spring Boot 2 Maven 项目在 Intellij 上运行但不在 Tomcat 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52989351/