简体   繁体   中英

Spring boot app won't start on Tomcat Server

I am trying to deploy a spring boot application as a WAR to a tomcat server. I can build and deploy the war to the tomcat server just fine. When I start the server though my spring application never runs. The server starts up just fine. I have done everything Spring says to do here,

http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file

My project has its own custom Parent POM and consists of 2 modules.

I have read several other similar threads and as far as I can tell I have everything set up properly but clearly something is wrong. Any help would be much appreciated.

THank You!

Parent pom

<groupId>com.project</groupId>
<artifactId>TelematicsNotificationSystem</artifactId>
<name>TelematicsNotificationSystem</name>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
    <java.version>1.8</java.version>
    <artifact-deployer.version>2.0.0-RELEASE</artifact-deployer.version>
    <cxf.version>2.5.2</cxf.version>
    <start-class>com.project.TNS.TelematicsNotificationSystem</start-class>
</properties>

<modules>
    <module>TelematicsNotificationSystem-wsclient</module>
    <module>TelematicsNotificationSystem-web</module>
</modules>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
        <version>1.5.0.RELEASE</version>
    </dependency>

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

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

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

    <dependency>
        <groupId>com.sun.mail</groupId>
        <artifactId>javax.mail</artifactId>
        <version>1.5.6</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.ldap</groupId>
        <artifactId>spring-ldap-core</artifactId>
        <version>1.3.0.RELEASE</version>
    </dependency>       
</dependencies>

Web Project Pom

<artifactId>TelematicsNotificationSystem-Web</artifactId>
<name>TelematicsNotificationSystem-Web</name>
<packaging>war</packaging>


<parent>
    <groupId>com.project</groupId>
    <artifactId>TelematicsNotificationSystem</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</parent>

<properties>
    <start-class>com.project.TNS.TelematicsNotificationSystem</start-class>
</properties>



<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <resources>
                <resource>
                    <filtering>true</filtering>
                    <directory>src/main/resources/</directory>
                </resource>
                </resources>
            </configuration>
        </plugin>
    </plugins>
</build>

My Application Class

package TNS;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;

@SpringBootApplication
public class TelematicsNotificationSystem extends SpringBootServletInitializer{

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

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(TelematicsNotificationSystem.class);
}

}

Remember to refresh the application once deployed in Tomcat. It may be working well and only a refresh is needed.

Although I agree with Deinum that I needed to clean up my Pom that was not the overall fix. The fix was to simply add a component scan to my class which contained my main method.

@SpringBootApplication
@ComponentScan(basePackageClasses = DashBoardController.class)
public class TelematicsNotificationSystem extends SpringBootServletInitializer

The starting app couldn't find the Controller so it could handle any of my mapping requests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM