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>