简体   繁体   中英

No method readResolve when enabling spring-data-jpa repositories

I am trying to enable spring data JPA in my webapp, but I am having an issue upon enabling the spring jpa repositories.

I am using:

  • Spring 4.2.5
  • spring-data-jpa 1.9.4
  • Hibernate 5
  • JPA 2 (have also tried 2.1)
  • Tomcat 7.0.67

My applicationContext.xml contains:

    <!--
            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" />

My persistence.xml contains:

<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>

Every time I enable the jpa:repositories tag in the applicationContext.xml, I get the following exception:

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

It looks like some kind of serialization issue, but I can't for the life of me find what is causing it.

This turned out to be an issue with using AspectJ weaving. I added an exclusion filter for my domain model classes and the issue went away.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM