I want to create a war file from a Spring Boot application, which I can deploy to a standalone Tomcat container, not using the embedded one.
I can create the war file and run it on its own using "java -jar pdfjs-annotator.war"
and it works fine.
I built the application using gradle bootRepackage
(Using Gradle, Tomcat7, Java 1.7).
But when I deploy the war file to a standalone Tomcat and start it, the app seems to boot without errors according to the log, but I cannot access any of the resources nor do the controller urls work.
For example, my index.html is a static html page under src/main/resources/static/index.html, which I can usually call via localhost:8080/index.html, but when deployed to a standalone Tomcat, the page does not get delivered (it's then in the war file in WEB-INF/classes/static/index.html) through that same url. And also any kind of controller mapping don't seem to work. I am getting a 404 error instead.
build.gradle:
buildscript {
ext {
springBootVersion = '1.2.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("io.spring.gradle:dependency-management-plugin:0.5.0.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
war {
baseName = 'pdfjs-annotator'
version = '1.0.0-SNAPSHOT'
}
allprojects {
apply plugin: 'java'
sourceCompatibility = 1.6
targetCompatibility = 1.6
}
repositories {
mavenCentral()
}
configurations {
providedRuntime
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-data-rest")
compile("org.springframework.boot:spring-boot-starter-web")
runtime("mysql:mysql-connector-java")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
testCompile("org.springframework.boot:spring-boot-starter-test")
compile ('org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final')
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
My main application class:
@EnableJpaRepositories
@SpringBootApplication
public class PdfAnnotator extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(PdfAnnotator.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(PdfAnnotator.class);
}
}
When I look into the exploded war, I do see the following META-INF/MANIFEST.MF:
Manifest-Version: 1.0
Start-Class: com.mypackage.pdfcomment.PdfAnnotator
Spring-Boot-Version: 1.2.3.RELEASE
Main-Class: org.springframework.boot.loader.WarLauncher
The gradle build process usually generated two war artifacts, one named .war and one named .war.original - the .war is the one that holds proper MANIFEST.MF entries and it's the one I used to deploy to the standalone Tomcat.
What's missing? I already checked other questions here on SO:
and also the Spring Boot docs, but could not find a hint of what's wrong.
* === Update === *
I installed a brand new Tomcat7, deployed the war file there, and everything's working fine. Seemed to be some issue with the Tomcat instance/configuration I had running. Not sure what exactly the issue was, but I won't bother to check it further since it's working fine now with the new Tomcat.