Spring Boot禁用在WAR部署中创建JpaProperties配置

时间:2018-04-18 15:14:56

标签: spring spring-boot spring-data spring-data-jpa

我试图设置一个使用EclipseLink而不是Hibernate的Spring Boot应用程序。该项目具有与此示例项目类似的结构:

https://github.com/spring-projects/spring-data-examples/blob/master/jpa/eclipselink/src/main/java/example/springdata/jpa/eclipselink/Application.java

主要区别在于我们的应用程序需要打包为WAR ...所以主要的Application.java扩展SpringBootServletInitializer而不是示例中显示的JpaBaseConfiguration(我们有另一个bean @Configuration扩展JpaBaseConfiguration)。

当应用程序启动时,遇到来自Hibernate的命名策略的ClassNotFoundException:

Error creating bean with name 'spring.jpa-org.springframework.boot.autoconfigure.orm.jpa.JpaProperties': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/boot/model/naming/ImplicitNamingStrategy

似乎只有当应用程序从SpringBootServletInitializer扩展时才会发生这种情况。

打开调试显示:

JpaBaseConfiguration.JpaWebConfiguration:
      Did not match:
         - @ConditionalOnProperty (spring.jpa.open-in-view=true) found different value in property 'open-in-view' (OnPropertyCondition)
      Matched:
         - @ConditionalOnClass found required class 'org.springframework.web.servlet.config.annotation.WebMvcConfigurer'; @ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
         - found ConfigurableWebEnvironment (OnWebApplicationCondition)

有没有办法排除JpaWebConfiguration,但仍然可以从SpringBootServletInitializer扩展应用程序?

更新:在进一步调试之后,我不相信JpaWebConfiguration是问题,因为这是调试中无法匹配的部分,但是仍然会导致创建JpaProperties bean并且遇到ClassNotFoundException。

0 个答案:

没有答案