gpt4 book ai didi

java - 启用 spring-data-jpa 存储库时没有方法 readResolve

转载 作者:太空宇宙 更新时间:2023-11-04 12:46:51 31 4
gpt4 key购买 nike

我正在尝试在我的 web 应用程序中启用 spring data JPA,但在启用 spring jpa 存储库时遇到问题。

我正在使用:

  • Spring 4.2.5
  • spring-data-jpa 1.9.4
  • hibernate 5
  • JPA 2(也尝试过 2.1)
  • Tomcat 7.0.67

我的applicationContext.xml包含:

    <!--
Activates a load-time weaver for the context. Any bean within the context that
implements LoadTimeWeaverAware (such as LocalContainerEntityManagerFactoryBean)
will receive a reference to the auto-detected load-time weaver.
-->
<context:load-time-weaver aspectj-weaving="on" />
<!-- Use this to specify exactly which load-time weaver should be used, but
it should get auto-detected. -->
<!-- <context:load-time-weaver aspectj-weaving="on" weaver-class="org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver" /> -->

<!-- Configurer that replaces ${...} placeholders with values from a properties file -->
<!-- (in this case, JDBC-related settings for the dataSource definition below) -->
<context:property-placeholder location="classpath:/META-INF/lf.properties" />

<!-- Apply dependency injection to non-managed classes annotated with the @Configurable -->
<context:spring-configured />

<!-- Auto scan and load Spring components -->
<context:component-scan base-package="com.lf" />

<!-- Transaction manager for a single JPA EntityManagerFactory (alternative to JTA) -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory" depends-on="entityManagerFactory" />

<!-- JPA EntityManagerFactory -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="${jpa.showSql}" />
<property name="database" value="${jpa.database}" />
</bean>
</property>
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
</property>
<!-- configure Hibernate to participate in JTA transactions using the JOTM transaction manager and
specify further Hibernate specific configuration properties -->
<property name="jpaPropertyMap">
<map>
<!-- Database Configuration -->
<entry key="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect" />
<entry key="hibernate.hbm2ddl.auto" value="${hibernate.hbm2ddl.auto}" />
<entry key="hibernate.format_sql" value="false" />
<entry key="hibernate.use_sql_comments" value="true" />
<entry key="hibernate.ejb.metamodel.generation" value="enabled" />
<entry key="hibernate.default_batch_fetch_size" value="50" />
<entry key="hibernate.order_updates" value="true" />
<!-- READ_COMMITTED -->
<entry key="hibernate.connection.isolation" value="2" />

<!-- Transaction Management -->
<!-- <entry key="hibernate.current_session_context_class" value="org.hibernate.context.ThreadLocalSessionContext" /> -->
<entry key="hibernate.current_session_context_class" value="org.springframework.orm.hibernate5.SpringSessionContext" />

</map>
</property>

</bean>

<!-- Enable Spring Data repositories -->
<jpa:repositories base-package="com.lf.repository"
entity-manager-factory-ref="entityManagerFactory"
transaction-manager-ref="transactionManager" />

我的 persistence.xml 包含:

<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

<persistence-unit name="LeapforcePU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
</persistence-unit>
</persistence>

每次在 applicationContext.xml 中启用 jpa:repositories 标记时,都会出现以下异常:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Method [readResolve] was discovered in the .class file but cannot be resolved in the class object
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
...
...
Caused by: java.lang.NoSuchMethodException: com.lf.model.experiment.CustomerGroup.readResolve()
at java.lang.Class.getDeclaredMethod(Class.java:2130)
at org.springframework.core.LocalVariableTableParameterNameDiscoverer$LocalVariableTableVisitor.resolveMember(LocalVariableTableParameterNameDiscoverer.java:245)
... 90 more

它看起来像是某种序列化问题,但我一生都无法找到导致它的原因。

最佳答案

事实证明,这是使用 AspectJ 编织的问题。我为域模型类添加了排除过滤器,问题就消失了。

关于java - 启用 spring-data-jpa 存储库时没有方法 readResolve,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36228505/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com