5

I'm creating a Spring Boot WAR file and deploying in Tomcat 10 webapps. When I run the Tomcat server, the WAR file is not running.

POM File:

<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>com.demo</groupId>
      <artifactId>Demo</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <packaging>war</packaging>
      <properties>
            <java.version>1.8</java.version>
        </properties>
        
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.5.4.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-jdbc</artifactId>
            </dependency>
        
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
                <scope>provided</scope>
            </dependency>
            
            <dependency>
                <groupId>com.oracle</groupId>
                <artifactId>ojdbc6</artifactId>
                <version>11.2.0.3</version>
            </dependency>
        
        </dependencies>
        
        <build>
      <plugins>
        <plugin>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
      </plugins>
    </build>
</parent>

Java File:

@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer{
    
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(DemoApplication.class);
    }

    public static void main(String[] args) {
    
        SpringApplication.run(DemoApplication.class, args);

    }
}

Is it anything related to Tomcat compatibility with Spring Boot? I have run the same file on Tomcat 8, it is working fine.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
bollam_rohith
  • 334
  • 4
  • 17
  • 4
    Tomcat10 is using JakartaEE and not JavaEE and isn't compatible. – M. Deinum Nov 23 '20 at 12:05
  • 1
    Why to use an external Tomcat10 when Spring Boot already comes with an embeded server and have the opportunity to embed some others, please check [this](https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/howto-embedded-web-servers.html) – Christian Blanco Nov 23 '20 at 12:12
  • @Deinum ThankYou. Can I useTomcat 9? – bollam_rohith Nov 23 '20 at 12:12
  • @Christian I need to build WAR file and deploy it on server. – bollam_rohith Nov 23 '20 at 12:13
  • @bollam_rohith Which server are you using? I mean, Where does your server is running? WindowsServer? Linux? The only think that you have to do to run a Spring Boot app is create the JAR file and run the java -jar command, will open the embeded server and will run without a problem. – Christian Blanco Nov 23 '20 at 12:18
  • 2
    @ChristianBlanco There can exists more complex ENVs with already configured applications servers, multiple apps etc. So SpringBoot is really cool during development phase or for simple production setup, but for complex production setup is war still needed. – sasynkamil Mar 08 '21 at 19:50
  • @bollam_rohith Yep, SpringBoot 2.x & Tomcat 9.x is working correctly. – sasynkamil Mar 08 '21 at 19:54
  • @sasynkamil it is not a rule that complex ENVS or complex projects have to be packaged in WAR files, that is wrong, normally today infra can be really complex and we, still, can work with Spring Boot's embedded tomcat, your comment does not make sense, but maybe just for legacy projects that were build before have an embedded tomcat. – Christian Blanco Mar 09 '21 at 02:29
  • @sasynkamil again, it is not a good practice to put a Spring Boot app into an external Tomcat since you have and embedded Tomcat already. Check first how are you going to build the infra before do that. Maybe Spring Boot is not for you in this case. – Christian Blanco Mar 09 '21 at 02:30
  • 1
    @ChristianBlanco 1) Author is asking how to run SB app on Tomcat, so your answer "The only think that you have to do to run a Spring Boot app is create the JAR file and run the java -jar command" is not answering question. 2) Ok, I should rather wrote "for traditional prod setup is war needed" 3) Nobody mentioned to have embedded Tomcat in war. If war is needed, then you can have maven profiles, so embedded Tomcat will not be part of build. 4) Yes, important is to follow doc & best practices: https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-traditional-deployment – sasynkamil Mar 10 '21 at 13:21

0 Answers0