我用Spring Boot实现了restful api。当我在Spring Boot Suite中使用嵌入式Tomcat服务器启动应用程序时,它可以正常工作。但是,当我尝试将战争部署到Tomcat 7时,我收到了以下错误:
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]]
我知道可能有数百种类似的帖子。在我研究了2天以上之后,这就是造成这种问题的主要原因。
我使用java 7编译并使用Tomcat 7进行部署。我确保为JAVA_HOME设置jre路径而不是jdk路径。
我有两个依赖并删除了2.0。
检查了pom的依赖层次结构,它们都是4.3.11.Final。
尝试在Tomcat Manager UI中部署。
这些都不适用于我的情况。尝试了一切,但没有任何效果。由于我使用的是Spring Boot,因此大多数配置都是自动完成的。我没有web.xml。我在主Application类之前有以下注释。
@SpringBootApplication
@EntityScan({"org.mdacc.rists.cghub.model"})
@EnableJpaRepositories(basePackages = {"org.mdacc.rists.cghub.ws.repository"})
在application.properties中,除了数据源配置之外,我还有以下几行。
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.EJB3NamingStrategy
spring.data.jpa.repositories.enabled=true
可能导致部署失败的任何其他可能原因?
答案 0 :(得分: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.