I have a Spring Boot webapp developed and tested with the Netbeans internal Tomcat server.
I have setup the Application as a 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);
}
}
with this 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>
I have built the war file (testspringboot2.war) with Netbeans and deployed it on the standalone Tomcat. It was successfully exploded.
But: I cannot reach it on http://tomcatserver:8088/testspringboot2
. Do I need to take care of anything else to make this work?
This is true for both Debian 12 and Windows 10 … so I think this is related to the Spring Boot project rather than the environment
2
Answers
You did not add the properties file, but have you checked the port you specify there? If I am not mistaken by default is 8080, so if you did not change it, it will not be available on 8088.
Additionally, you exposed an endpoint on
@GetMapping("/")
, but you are trying to reach on/testspringboot2
There are different ways how to override the default context path. Check, if any of them a not occasionally activated.
Find and evaluate XML elements
Context
especially in the following files:server.xml
orapp.xml
inside the Tomcat folder./META-INF/context.xml
inside the WAR file.You are looking for something like this:
More information:
https://tomcat.apache.org/tomcat-9.0-doc/config/context.html