Java Spring Boot - war文件未在Tomcat Apache上部署 [英] Java Spring Boot - war file not deploying on Tomcat Apache
问题描述
我正在构建一个Java Spring启动项目 - 作为一项要求,我需要将项目生成为war文件 - 然后让Tomcat Apache单独运行。
<我已经构建了war文件,但是当我尝试部署它时,就好像结构不正确并且它生成404试图查看项目。
- 问题
< a href =https://i.stack.imgur.com/M25PH.png =nofollow noreferrer>
-
my pom
http://maven.apache.org/xsd/maven-4.0.0.xsd>
4.0.0< groupId> org.springframework< / groupId>
< artifactId> gs-spring-boot< / artifactId>
< version> 0.1.0< / version>
< packaging> war< / packaging>
< parent>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-parent< / artifactId>
< version> 1.5.7.RELEASE< / version>
< / parent>
< dependencies>
<! - web - >
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-web< / artifactId>
< / dependency>
<! - test - >
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-test< / artifactId>
< scope> test< / scope>
< / dependency>
<! - Spring Security - >
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-security< / artifactId>
< / dependency>
<! - jpa - >
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-data-jpa< / artifactId>
< / dependency>
<! - https://mvnrepository.com/artifact/org.hibernate.javax.persistence/hibernate-jpa-2.0-api - >
< dependency>
< groupId> org.hibernate.javax.persistence< / groupId>
< artifactId> hibernate-jpa-2.0-api< / artifactId>
< version> 1.0.1.Final< / version>
< / dependency>
<! - mysql连接器 - >
< dependency>
< groupId> mysql< / groupId>
< artifactId> mysql-connector-java< / artifactId>
< / dependency>
<! - 邮件服务 - >
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-mail< / artifactId>
< / dependency>
<! - 热插拔,禁用模板缓存,启用实时重新加载 - >
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-devtools< / artifactId>
< optional> true< / optional>
< scope>提供< / scope>
< / dependency>
<! - freemarker template - >
< dependency>
< groupId> org.freemarker< / groupId>
< artifactId> freemarker< / artifactId>
< version> 2.3.23< / version>
< / dependency>
<! - json simple - >
< dependency>
< groupId> com.googlecode.json-simple< / groupId>
< artifactId> json-simple< / artifactId>
< version> 1.1.1< / version>
< / dependency>
<! - tag :: actuator [] - >
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-actuator< / artifactId>
< / dependency>
<! - end :: actuator [] - >
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-configuration-processor< / artifactId>
< optional> true< / optional>
< / dependency>
< dependency>
< groupId> com.h2database< / groupId>
< artifactId> h2< / artifactId>
< version> 1.4.194< / version>
< scope> test< / scope>
< / dependency>
< / dependencies>
< properties>
< java.version> 1.8< /java.version>
< / properties>
< build>
< plugins>
< plugin>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-maven-plugin< / artifactId>
< / plugin>
< plugin>
< artifactId> maven-failsafe-plugin< / artifactId>
< executions>
< execution>
< goals>
< goal> integration-test< / goal>
< goal>验证< / goal>
< / goals>
< / execution>
< / executions>
< / plugin>
< / plugins>
< / build>
要将Spring Boot部署为战争 - 您需要重新配置Application类。
< a href =https://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html#howto-create-a-deployable-war-file\"rel =nofollow noreferrer> https://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html#howto-create-a-deployable-war-file
@SpringBootApplication
公共类应用程序扩展SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder应用程序){
return application.sources(Application.class);
}
public static void main(String [] args)throws Exception {
SpringApplication.run(Application.class,args); pom.xml $ b中
}
}
$ b add
< packaging> war< / packaging>
因为我使用maven我也添加了依赖项。
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-tomcat< / artifactId>
< scope>提供< / scope>
< / dependency>
我的应用程序很复杂,因为我使用reactjs作为前端表示层而Java就像api层。我不得不将reactjs构建移动到main / src / webapps中 - 然后将其作为js,css和html文件包正确地呈现在war文件中。由于reactjs充当表示层,它只能通过api连接到java端 - 所以url结构很重要,我把所有东西放在预期它将从root运行。因此,如果部署到tomcat - 您可能需要重命名war文件ROOT.war。
I am building a Java Spring boot project - and as a requirement I need to generate the project as a war file - and then have Tomcat Apache run from this alone.
I've built the war file, but when I try to deploy it, its as if the structure is incorrect and its generating a 404 trying to view the project.
- the problem
my pom
http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0
<groupId>org.springframework</groupId> <artifactId>gs-spring-boot</artifactId> <version>0.1.0</version> <packaging>war</packaging> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.7.RELEASE</version> </parent> <dependencies> <!-- web --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- test --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- Spring Security --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <!-- jpa --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/org.hibernate.javax.persistence/hibernate-jpa-2.0-api --> <dependency> <groupId>org.hibernate.javax.persistence</groupId> <artifactId>hibernate-jpa-2.0-api</artifactId> <version>1.0.1.Final</version> </dependency> <!-- mysql connector --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!-- mail service --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId> </dependency> <!-- hot swapping, disable cache for template, enable live reload --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> <scope>provided</scope> </dependency> <!-- freemarker template --> <dependency> <groupId>org.freemarker</groupId> <artifactId>freemarker</artifactId> <version>2.3.23</version> </dependency> <!-- json simple --> <dependency> <groupId>com.googlecode.json-simple</groupId> <artifactId>json-simple</artifactId> <version>1.1.1</version> </dependency> <!-- tag::actuator[] --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!-- end::actuator[] --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <version>1.4.194</version> <scope>test</scope> </dependency> </dependencies> <properties> <java.version>1.8</java.version> </properties> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <artifactId>maven-failsafe-plugin</artifactId> <executions> <execution> <goals> <goal>integration-test</goal> <goal>verify</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
To get Spring Boot to deploy as a war - you need to reconfigure the Application class.
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
in the pom.xml add
<packaging>war</packaging>
as I was using maven I also added the dependency.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
My application was complicated in that I was using reactjs as a frontend presentation layer and the Java just as an api layer. I had to move the reactjs build into main/src/webapps -- this then gets rendered in the war file correctly as bundle of js, css and html files. With the reactjs acting as a presentation layer it could only connect to the java side via the api - so the url structure is important and I had placed everything in anticipation it would run from the root. So if you deploy to tomcat - you may need to rename the war file ROOT.war.
这篇关于Java Spring Boot - war文件未在Tomcat Apache上部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!