1

There are a lot of moving parts to this project, but I'll try to be brief and objective.

Basically, I have a Spring Boot application that compiles and runs fine on Netbeans with Tomcat 7.0.63. I also runs without issues when I drag and drop the .war file generated on Netbeans, directly to the webapps/ folder on on the Tomcat directory.

However, when I try to deploy that same .war file to Tomcat 7.0.63 running on a remote server, all I get is the Tomcat 404 Error page.

No errors are generated on Catalina.out and the application is deployed successfully, but it seems to just point to the root application folder instead of loading the Spring DispatcherServlet. The reason I say this is because if I add a sample index.html to the root folder, it will render instead of the 404 error.

Here is my SpringBootServletInitializer:

@ComponentScan
@EnableAutoConfiguration
@SpringBootApplication
public class RecruitingDashboardApplication extends SpringBootServletInitializer {

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

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


}

And here is my WebMvcConfigurerAdapter:

@EnableAutoConfiguration
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

    @Bean 
    public ViewResolver viewResolver() {
        ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
        templateResolver.setPrefix("templates/");
        templateResolver.setSuffix(".html");

        SpringTemplateEngine engine = new SpringTemplateEngine();
        engine.setTemplateResolver(templateResolver);

        ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
        viewResolver.setTemplateEngine(engine);
        return viewResolver;
    }


    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("dashboard");
        registry.addViewController("/login").setViewName("login");
    }

}

It's also worth noting that I don't have a web.xml. Everything is either auto configured by Spring Boot or Java configured through the above files.

Finally, since I know this will come up on the comments, here is my pom.xml 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.mycompany</groupId>
<artifactId>RecruitingDashboard</artifactId>
<packaging>war</packaging>

<name>Recruiting Dashboard</name>

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

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
    <tomcat.version>7.0.63</tomcat.version>
    <start-class>recruitingdashboard.RecruitingDashboardApplication</start-class>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>net.sourceforge.nekohtml</groupId>
        <artifactId>nekohtml</artifactId>
        <version>1.9.22</version>
    </dependency>

</dependencies>

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

</project>
Pedro Hoehl Carvalho
  • 2,183
  • 2
  • 19
  • 25
  • I'm not sure that it's the cause of your problem, but [as described here](http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file) you need to mark the embedded Tomcat dependency as provided to stop it from interfering with servlet container that you're deploying to – Andy Wilkinson Aug 20 '15 at 14:19
  • Thanks for your comment. I have tried to mark it as provided and I also tried excluding the tomcat dependency as described on this [this answer](http://stackoverflow.com/questions/25991789/spring-boot-war-without-tomcat-embedded). Both still yield the same result. Catalina.out does not show any signs of starting spring boot at all. – Pedro Hoehl Carvalho Aug 20 '15 at 15:28
  • did you got the answer ? – Ajith Madhu Oct 10 '19 at 13:18

1 Answers1

0

Maybe a bit late, but somebody else might stumble upon this problem like i did myself.

Deploying on local tomcat worked fine for me, but when deploying on remote tomcat on ubuntu i got the Tomcat 404 Error page aswell.

I also tried deploying with

<java.version>1.8</java.version>

but without the tomcat version (i was using Apache Tomcat/7.0.52. for the reference).

After deploying with properties:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <start-class>controllers.Application</start-class>
</properties>

it worked like it should. Deploying with

<java.version>1.7</java.version>

worked aswell.