JimmyD
JimmyD

Reputation: 2759

Spring boot does not start in Tomcat instance

I have a small web application that only contains some scheduled task. When I deploy this app on a Tomcat instance nothing happens. No logs are generated, scheduling does not work. The only log I found of the application is:

31-Aug-2018 11:05:06.120 INFO [http-nio-80-exec-107] org.apache.catalina.core.ApplicationContext.log 1 Spring WebApplicationInitializers detected on classpath

I have following annotations to the application class (where main is in):

@SpringBootApplication
@EnableConfigurationProperties(InfluxProperties.class)
@EnableScheduling

The class where the scheduled task is in looks like:

@Component
public class MQMonitorTask {

    private Logger logger = LoggerFactory.getLogger(MQMonitorTask.class);

    /**
     * Get the MQ depth of all the queues and send it to Influx
     */
    @Scheduled(fixedDelay = 10000)
    public void getMQData() {
        logger.info("test");
        //Custom code here
    }
}

Pom file looks like:

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.atlascopco</groupId>
    <artifactId>PTITMonitorIntegrator</artifactId>
    <version>1.0.0</version>

    <name>PTITMonitorIntegrator</name>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.ibm</groupId>
            <artifactId>mq</artifactId>
            <version>1.0</version>
        </dependency>

        <dependency>
            <groupId>com.ibm</groupId>
            <artifactId>mq.allclient</artifactId>
            <version>1.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot</artifactId>
            <version>2.0.4.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>


        <dependency>
            <groupId>com.ibm</groupId>
            <artifactId>msg.client.commonservices.wmq</artifactId>
            <version>1.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
    <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
      <scope>provided</scope>
</dependency>

        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.6</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/org.influxdb/influxdb-java -->
        <dependency>
            <groupId>org.influxdb</groupId>
            <artifactId>influxdb-java</artifactId>
            <version>2.12</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


    <packaging>war</packaging>
    <description>Spring boot application that will query for information for PT-IT Monitor system</description>
</project>

Can someone help me to find this issue? When I create a jar file instead of a war file and run it with java -jar file.jar it just startup and works without any issue. But it is a requirement to run in on a Tomcat server.

Upvotes: 1

Views: 7580

Answers (2)

Adya
Adya

Reputation: 1112

Try to change jar to war in pom.xml

Upvotes: 1

Matthieu Gabin
Matthieu Gabin

Reputation: 952

Did you look at this spring-boot documentation Create a Deployable War File?

Does your application class extend SpringBootServletInitializer ?

Upvotes: 2

Related Questions