I am trying to deploy a Spring Boot app to Tomcat. I created a WAR file, but it does not run on Tomcat, even though it is visible.
build.gradle
plugins {
id 'java'
id 'war'
id 'org.springframework.boot' version '3.2.5'
id 'io.spring.dependency-management' version '1.1.4'
}
group = 'com.test.chatsystem'
java {
sourceCompatibility = '17'
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
}
tasks.named('test') {
useJUnitPlatform()
}
war {
archivesBaseName = 'socialmedia'
}
task build(overwrite: true) {
dependsOn = ['clean','test','war']
test.mustRunAfter clean
war.mustRunAfter test
}
Application file –
package com.application.chatsystem.socialmedia;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Controller file –
package com.intuit.chatsystem.socialmedia.controller;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class StatusController {
@GetMapping("/rest/status")
public ResponseEntity<String> getStatus() {
return ResponseEntity.ok("Working");
}
}
server.xml file –
<Server port="-1" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener"/>
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
<Service name="Catalina">
<Connector port="8080" maxHttpHeaderSize="8192"
connectionTimeout="20000" maxThreads="2000"
enableLookups="false"
URIEncoding="utf-8"
/>
<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context path="/" docBase="ROOT" reloadable="true"/>
</Host>
</Engine>
</Service>
</Server>
Tried multiple options but not working. Please help what else I can do to make it working.
Springboot war is not successfully deployed and it is starting. API’s are not accessible
Getting 404 while accessing.
API’s endpoints are not accessible.