Spring 启动应用程序 - Tomcat 部署
Spring boot application - Tomcat deployment
我在将我的 spring 启动应用程序部署到 tomcat 时遇到问题,尽管在我的 IDE 上运行良好。
我按照 https://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html
的说明进行操作
但结果我得到了一个 war 包,只包含框架库和网络 类,没有来自我的核心模块。
我不确定我的 pom 文件是否正确。
我的项目结构如下所示:
portal
-web
-src
pom1.xml
-core
-src
pom2.xml
pom0.xml
项目 pom (pom0.xml):
<modules>
<module>core</module>
<module>web</module>
<module>tests</module>
</modules>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
网络模块 pom (pom1.xml):
<parent>
<artifactId>portal</artifactId>
<groupId>com.portal</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>web</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.portal</groupId>
<artifactId>core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
核心模块pom(pom2.xml)
<parent>
<artifactId>portal</artifactId>
<groupId>com.portal</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>core</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>com.custom.api</groupId>
<artifactId>common-utils</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
更新 1
更详细的结构:
-web
-com.portal.web
-controller
IncidentController
ComputerController
...
-core
-com.portal.core
-domain
Incident
Computer
...
mvn clear package 给出错误:
[INFO] portal ............................................. SUCCESS [ 0.700 s]
[INFO] core ............................................... SUCCESS [ 2.478 s]
[INFO] web ................................................ FAILURE [ 0.458 s]
[INFO] tests .............................................. SKIPPED
...
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project web: Compilation failure: Compilation failure:
[ERROR] /.../portal/web/src/main/java/com/portal/web/controller/IncidentController.java:[4,37] package com.portal.core.domain does not exist
[ERROR] /.../portal/web/src/main/java/com/portal/web/controller/IncidentController.java:[5,38] package com.portal.core.service does not exist
[ERROR] /.../portal/web/src/main/java/com/portal/web/controller/IncidentController.java:[18,19] cannot find symbol
[ERROR] symbol: class IIncidentService
[ERROR] location: class com.portal.web.controller.IncidentController
...
将 "web module" 添加到父 "portal module" 的模块部分:
<modules>
<module>core</module>
<module>api</module>
<module>tests</module>
<module>web</module>
</modules>
运行 mvn clean package
在父文件夹中 "portal module"。
多模块项目的解决方案是配置Boot的重新打包以对jar应用分类器:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
问题的完整描述是here
我在将我的 spring 启动应用程序部署到 tomcat 时遇到问题,尽管在我的 IDE 上运行良好。 我按照 https://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html
的说明进行操作但结果我得到了一个 war 包,只包含框架库和网络 类,没有来自我的核心模块。
我不确定我的 pom 文件是否正确。
我的项目结构如下所示:
portal
-web
-src
pom1.xml
-core
-src
pom2.xml
pom0.xml
项目 pom (pom0.xml):
<modules>
<module>core</module>
<module>web</module>
<module>tests</module>
</modules>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
网络模块 pom (pom1.xml):
<parent>
<artifactId>portal</artifactId>
<groupId>com.portal</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>web</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.portal</groupId>
<artifactId>core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
核心模块pom(pom2.xml)
<parent>
<artifactId>portal</artifactId>
<groupId>com.portal</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>core</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>com.custom.api</groupId>
<artifactId>common-utils</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
更新 1
更详细的结构:
-web
-com.portal.web
-controller
IncidentController
ComputerController
...
-core
-com.portal.core
-domain
Incident
Computer
...
mvn clear package 给出错误:
[INFO] portal ............................................. SUCCESS [ 0.700 s]
[INFO] core ............................................... SUCCESS [ 2.478 s]
[INFO] web ................................................ FAILURE [ 0.458 s]
[INFO] tests .............................................. SKIPPED
...
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project web: Compilation failure: Compilation failure:
[ERROR] /.../portal/web/src/main/java/com/portal/web/controller/IncidentController.java:[4,37] package com.portal.core.domain does not exist
[ERROR] /.../portal/web/src/main/java/com/portal/web/controller/IncidentController.java:[5,38] package com.portal.core.service does not exist
[ERROR] /.../portal/web/src/main/java/com/portal/web/controller/IncidentController.java:[18,19] cannot find symbol
[ERROR] symbol: class IIncidentService
[ERROR] location: class com.portal.web.controller.IncidentController
...
将 "web module" 添加到父 "portal module" 的模块部分:
<modules>
<module>core</module>
<module>api</module>
<module>tests</module>
<module>web</module>
</modules>
运行 mvn clean package
在父文件夹中 "portal module"。
多模块项目的解决方案是配置Boot的重新打包以对jar应用分类器:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
问题的完整描述是here