gpt4 book ai didi

java - Spring Boot部署WAR

转载 作者:行者123 更新时间:2023-11-30 03:08:41 25 4
gpt4 key购买 nike

我有一个工作的 Spring Boot 应用程序,当我创建 JAR 文件并执行它时,它可以正常工作。

但是当我遵循这个 tutorial 时要在 tomcat 上部署 WAR,我无法访问 Controller 。我不确定路径。我尝试了 localhost:8080/appname/controllervalue它没有给出任何响应,我也没有看到错误。

我打开了 webapps 文件夹并检查了内容。我找到了一个 web.xml 文件,并且那里的路径是空的。所以我尝试了 localhost:8080/controllervalue ,但这也不起作用。我缺少什么吗?

我的pom文件

<?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>com.intbit</groupId>
<artifactId>ImageRXWebServices</artifactId>
<version>1</version>
<packaging>war</packaging>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.7.RELEASE</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.2.3.RELEASE</version>
<type>jar</type>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.3-1102-jdbc41</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>javax.transaction-api</artifactId>
<version>1.2</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.1.8.RELEASE</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.1.8.RELEASE</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.1.8.RELEASE</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
<type>jar</type>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<tomcat.version>8.0.3</tomcat.version>
</properties>

<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

最佳答案

如果您正在构建 war 文件并部署它,则需要添加 WebApplicationInitializer SpringBootServletInitializer

在sping boot中可以使用SpringBootServletInitializer

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

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

}

关于java - Spring Boot部署WAR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34134809/

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