Spring War boot file works with built-in, but not standalone Tomcat

I want to create a war file from a Spring application for download, which I can deploy to a standalone Tomcat container without using the built-in.

I can create a war file and run it myself 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 stand-alone Tomcat and run it, the application seems to load without errors according to the log, but I can’t access any resources and work with the controller URLs.

For example, my index.html is a static html page in src / main / resources / static / index.html, which I usually call through localhost: 8080 / index.html, but when deployed to stand-alone Tomcat, the page is not delivered (it then in the military file in WEB-INF / classes / static / index.html) via the same URL. And also any display of the controller does not work. Instead, I get a 404 error.

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 :

 @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 at the blown up war, I 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 generates two military artifacts: one named .war and one named .war.original -.war is the one that contains the corresponding MANIFEST.MF entries, and the one I used to deploy the stand-alone Tomcat.

What is missing? I already checked here for other SO questions here:

as well as Spring Boot documents, but could not find a hint of what's wrong.

* === Update === *

I installed the new Tomcat7, deployed a war file there and everything worked fine. It seemed that I had a problem with the instance / configuration of Tomcat. Not sure what the problem is, but I will not worry about it, because now it works fine with the new Tomcat.

+6
source share
3 answers

The project was really set up correctly, and it turned out that the problem was with the Tomcat instance that I was running. Maybe something is wrong with the configuration or the jars. The instance already exists for a long time, perhaps things have gotten messy over time.

Now that the new Tomcat7 instance is installed, the war is just fine.

0
source

I had this exact problem. This was because my application was built using Java 1.8, but Tomcat worked with 1.7. Everything turned out to be correctly deployed, and there were no errors. I just got 404 trying to hit my services that would otherwise be nice with the tomcat built-in server. He demanded me to understand this, but it was just a case of updating java on a Tomcat installation.

+1
source

Could you provide more details on how you install WAR? Spring Boot requires a basic method that must be specified explicitly:

 <packaging>war</packaging> ... <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> <configuration> <mainClass>your.app.class.with.Main</mainClass> </configuration> </execution> </executions> </plugin> 
-1
source

Source: https://habr.com/ru/post/986879/


All Articles