我正在将 Spring Data 与 Hibernate 和 mongo db 一起使用。我在尝试将我的 web 应用程序部署到 Wildfly 10 时遇到以下堆栈。
引起:java.lang.IllegalArgumentException:不是托管类型:org.hibernate.jpa.internal.metamodel.MetamodelImpl.managedType(MetamodelImpl.java:219) 的类 com.olp.jpa.domain.docu.product.ProductTemplateBean在 org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.(JpaMetamodelEntityInformation.java:68) 在 org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getMetadata(JpaEntityInformationSupport.java:65) 在 org.springframework。 data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:149) 在 org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:88) 在 org.springframework.data.jpa。 repository.support.JpaRepositoryFactory。getTargetRepository(JpaRepositoryFactory.java:68) at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:159) at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport. java:224) 在 org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92) 在 org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:210)在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory 的 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)。initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ... 还有 35 个
使用 SpringJUnit4ClassRunner 在 Junit 中测试时,代码运行良好。只有在 Wildfly 部署期间,我才会收到此错误。以下各种工件的片段:
web.xml
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/classes/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
弹簧配置
http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx。 xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/jdbc http:// www.springframework.org/schema/jdbc/spring-jdbc.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa。 xsd "
<context:component-scan base-package="com.olp"/> <tx:annotation-driven /> <jpa:repositories base-package="com.olp.jpa.domain" entity-manager-factory-ref="entityManagerFactory"/> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="persistenceUnitManager" ref="persistenceUnitMgr"/> <property name="jpaDialect" ref="jpaDialect"/> <property name="jpaVendorAdapter" ref="ogmVendorAdapter"/> </bean> <bean id="persistenceUnitMgr" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager"> <property name="persistenceUnitPostProcessors"> <array> <ref bean="persistencePostProcessor"/> </array> </property> <property name="persistenceXmlLocation" value="classpath:META-INF/persistence_olp.xml"/> <property name="defaultPersistenceUnitName" value="productHub"/> <property name="packagesToScan" value="com.olp.jpa.domain.docu" /> </bean> <bean id="persistencePostProcessor" class="com.olp.jpa.OlpPersistenceUnitPostProcessor"/> <bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/> <bean id="ogmVendorAdapter" class="com.olp.jpa.OlpHibernateOgmVendorAdapter"/>
JPA 配置 (persistence_olp.xml)
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> org.hibernate.ogm.jpa.HibernateOgmPersistence ENABLE_SELECTIVE
<properties> <!-- All other hibernate / mongo properties are externalized and provided by persistence unit post-processor in Spring --> <property name="jboss.as.jpa.managed" value="false" /> </properties>
实体抛出异常 (ProductTemplateBean.java)
包 com.olp.jpa.domain.docu.product;
@Entity @Table(name="phub_product_template") 公共类 ProductTemplateBean 实现可序列化 {
@Id @DocumentId @GeneratedValue(strategy = GenerationType.AUTO) //@Type(type = "objectid") private Long id; // Omitting other fields & getters setters for brevity
}
Wildfly 类加载器配置 (jboss-deployment-structure.xml)
<exclusions> <module name="org.hibernate"/> <module name="org.hibernate.search.orm"/> <module name="org.hibernate.search.engine"/> <module name="org.hibernate.validator"/> <module name="org.codehaus"/> <module name="resteasy" /> </exclusions> </deployment>
如果有人可以提出一些指示,我将不胜感激。我已经阅读了一些相关文章,其中大部分都指向“packagesToScan”属性。这已经正确配置。
头疼了好久!在此先感谢您提供的任何帮助。