我有一个使用 Netbeans 内部 Tomcat 服务器开发和测试的 Spring Boot Web 应用程序。
我已将应用程序设置为 SpringBootServletInitializer
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Testspringboot2Application.class);
}
}
@SpringBootApplication
@RestController
public class Testspringboot2Application {
@GetMapping("/")
public String greeting() {
return "Hello from root path";
}
public static void main(String[] args) {
SpringApplication.run(Testspringboot2Application.class, args);
}
}
用这个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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>org.theiner</groupId>
<artifactId>testspringboot2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>testspringboot2</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>21</java.version>
</properties>
<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.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
我已经使用 Netbeans 构建了 war 文件(testspringboot2.war)并将其部署在独立的 Tomcat 上。爆炸成功了。
但是:我无法在
http://tomcatserver:8088/testspringboot2
上到达它。我还需要处理其他事情才能完成这项工作吗?
对于 Debian 12 和 Windows 10 都是如此……所以我认为这与 Spring Boot 项目而不是环境有关
您没有添加属性文件,但您检查过您在其中指定的端口吗?如果我没记错的话默认是8080,所以如果你不改的话,在8088上是无法使用的。
此外,您在
@GetMapping("/")
上暴露了一个端点,但您正试图到达 /testspringboot2