I am trying to deploy a rest sample in external tomcat. However, it does not give any error and Spring does not start also. According to Spring documentation I followed three steps
- Packages as war inside pom.xml
<scope>provided</scope>
to spring-boot-starter-tomcat in pom.xml- Extending main class with SpringBootServletInitializer
When I place this in Tomcat's webapp folder and run "catalina.bat run" it says application deployed successfully, but whatever URL I try to access, it does not execute the rest method
@SpringBootApplication
@RestController
public class HelloWorldApplication extends SpringBootServletInitializer
{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application)
{
return application.sources(HelloWorldApplication.class);
}
public static void main(String[] args)
{
SpringApplication.run(HelloWorldApplication.class, args);
}
@RequestMapping(value = "/hello")
public String helloWorld()
{
return "Hello World, Peter";
}
}
and in pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<groupId>com.example</groupId>
<artifactId>HelloWorld</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>HelloWorld</name>
<description>Demo project for Spring Boot</description>
<packaging>war</packaging>
and application.properties is like
server.servlet.context-path=/sample
Tomcat logs:
15-Mar-2020 23:06:46.219 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [C:\softwares\apache-tomcat-10.0.0-M1\webapps\HelloWorld-0.0.1-SNAPSHOT.war]
15-Mar-2020 23:06:48.102 INFO [main] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
15-Mar-2020 23:06:48.409 WARNING [main] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [270] milliseconds.
15-Mar-2020 23:06:48.440 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [C:\softwares\apache-tomcat-10.0.0-M1\webapps\HelloWorld-0.0.1-SNAPSHOT.war] has finished in [2,221] ms
I tried accessing in below ways.but none of them worked.Could any one points me in right direction?
localhost:8080/HelloWorld-0.0.1-SNAPSHOT
localhost:8080/HelloWorld-0.0.1-SNAPSHOT/hello
localhost:8080/HelloWorld-0.0.1-SNAPSHOT/HelloWorldApplication/helloWorld