ddd
ddd

Reputation: 5029

LifecycleException: Failed to start component deploying war in Tomcat

I implemented restful api with Spring Boot. It works when I start the application within Spring Boot Suite with embeded Tomcat server. However when I tried to deploy the war to Tomcat 7, I got the following errors:

SEVERE: Exception fixing docBase for context [/cgweb]
java.io.FileNotFoundException: /Users/djiao/Downloads/apache-tomcat-7.0.68/webapps/cgweb/LICENSE (Is a directory)

SEVERE: ContainerBase.addChild: start: 
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/cgweb]]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey;
Caused by: java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey;

SEVERE: Error deploying web application archive /Users/djiao/Downloads/apache-tomcat-7.0.68/webapps/cgweb.war
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina
].StandardHost[localhost].StandardContext[/cgweb]]

I know there are probably hundreds of similar type of posts. After I have been researching for more than 2 days, here are the major causes of such problem.

  1. Tomcat version does not match java compiler version.

I compiled with java 7 and used Tomcat 7 for deploy. I made sure I set jre path for JAVA_HOME not jdk path.

  1. Conflict between jpa 2.0 and 2.1 (related to the Foreign key error).

I had both in my dependency and removed 2.0.

  1. Version mismatch between hibernate-entitymanger and hibernate-core.

Checked the dependency hierarchy of the pom, they are both 4.3.11.Final.

  1. Deployed by copying the war to webapp folder manually.

Tried to deploy in Tomcat Manager UI.

None of these applied to my case. Tried everything and yet nothing worked. Since I am using Spring Boot, most of the configuration was done automatically. I do not have a web.xml. I have the following annotations before main Application class.

@SpringBootApplication
@EntityScan({"org.mdacc.rists.cghub.model"}) 
@EnableJpaRepositories(basePackages = {"org.mdacc.rists.cghub.ws.repository"})

In application.properties, I have the following lines other than datasource configs.

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.EJB3NamingStrategy
spring.data.jpa.repositories.enabled=true

Any other possible reason that could cause the deploy failure?

Upvotes: 0

Views: 1784

Answers (1)

To summarize the issue, the war file has both jpa 2.0 and 2.1 jar files even after deleting the maven dependency for jpa 2.0 from this project.

The reason being, jpa 2.0 was picked from another project which is one of the dependencies of this project. Doing a maven clean (after removing the jpa 2.0) for that dependency package and rebuilding it again solved the issue.

Upvotes: 1

Related Questions