gpt4 book ai didi

web-services - spring boot部署外部tomcat

转载 作者:行者123 更新时间:2023-11-28 22:27:52 26 4
gpt4 key购买 nike

我正在使用 spring boot 和一个简单的 hello world Controller 。我想将它部署到外部 tomcat 服务器。我注意到 web.xml 文件丢失了。我希望在 web-inf 目录中看到这个文件。在内部运行 spring boot 时(使用 spring boot 的内部 tomcat,它可以工作。但我想将我的应用程序部署到外部 tomcat 服务器。

将 war 文件部署到外部 tomcat 服务器后,我可以在可用服务列表中看到 hello world,但我无法使用 hello world 服务 - 我收到 404 错误消息。

我正在使用 maven、Jdk 1.8、IntelliJ

这是我的 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>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.3.1.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-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.3.9</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.9.2.RELEASE</version>
</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-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<attachClasses>true</attachClasses>
</configuration>
</plugin>
</plugins>
</build>

</project>

这是我的应用程序类:

import java.util.Arrays;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}

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

System.out.println("Let's inspect the beans provided by Spring Boot:");

String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
}
}

将 hello world 应用程序部署到外部 tomcat 服务的正确方法是什么?

最佳答案

在 tomcat 上部署时,应该有一个由容器添加的上下文路径,并且必须作为第一个元素路径包含在您的 URL 中。检查 tomcat 启动日志以获取上下文路径并按指示重试调用服务。

关于web-services - spring boot部署外部tomcat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34405318/

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