java.lang.IllegalAccessException-无法使用修饰符“”访问类org.springframework.data.jpa.util.HibernateProxyDetector的成员

时间:2018-12-07 14:38:28

标签: spring-data-jpa

基本Spring Data JPA应用程序(不是Spring BOOT应用程序)。是否有人知道可能导致此问题的原因: 错误:

static

以下是有关事件的详细信息:

pom.xml(仅使用boot-starter依赖项以使其易于使用。由于与Apache James的集成问题,它不是Spring Boot应用程序)

at org.springframework.beans.factory.annotation.
InitDestroyAnnotationBeanPostProcessor$LifecycleElement
.invoke(InitDestroyAnnotationBeanPostProcessor.java:344)
at org.springframework.beans.factory
.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.
invokeInitMethods
(InitDestroyAnnotationBeanPostProcessor.java:295)
    at org.springframework.beans.factory.
annotation.InitDestroyAnnotationBeanPostProcessor.
postProcessBeforeInitialization
(InitDestroyAnnotationBeanPostProcessor.java:130)
    ... 16 more
Caused by: java.lang.IllegalArgumentException: 
Cannot instantiate factory class: 
org.springframework.data.util.ProxyUtils$ProxyDetector
    at org.springframework.core.io.
support.SpringFactoriesLoader.instantiateFactory
(SpringFactoriesLoader.java:117)
    at org.springframework.core.io.support.
SpringFactoriesLoader.loadFactories
(SpringFactoriesLoader.java:80)
    at org.springframework.data.util.ProxyUtils.
<clinit>(ProxyUtils.java:40)
    ... 49 more
Caused by: java.lang.IllegalAccessException: Class 
org.springframework.core.io.support.SpringFactoriesLoader 
can not access a member of class 
org.springframework.data.jpa.util.HibernateProxyDetector with modifiers ""
    at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102)
    at java.lang.Class.newInstance(Class.java:436)
    at org.springframework.core.io.support.
SpringFactoriesLoader.instantiateFactory(SpringFactoriesLoader.java:114)

配置:

<parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.1.1.RELEASE</version>
      <relativePath /> <!-- lookup parent from repository -->
</parent>

<dependency>
        <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

存储库:

 @Bean
 LocalContainerEntityManagerFactoryBean entityManagerFactory() {
     LocalContainerEntityManagerFactoryBean lfb = new 
 LocalContainerEntityManagerFactoryBean();
     lfb.setDataSource(dataSource());
 lfb.setPersistenceProviderClass
 (org.hibernate.jpa.HibernatePersistenceProvider.class);
     lfb.setPackagesToScan("com.######.######.model");
     lfb.setJpaProperties(hibernateProps());
     return lfb;
 }

 Properties hibernateProps() {
     Properties properties = new Properties();
     properties.setProperty("hibernate.dialect",
 "org.hibernate.dialect.MySQL5InnoDBDialect");
     properties.setProperty("hibernate.show_sql","true");
     return properties;
 }
 @Bean
 JpaTransactionManager transactionManager() {
     JpaTransactionManager transactionManager = new JpaTransactionManager();
     transactionManager.setEntityManagerFactory(
 entityManagerFactory().getObject());
     return transactionManager;
 } 
 @Bean
 public DataSource dataSource() {
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://mysql-james:3306/mailv2? 
 autoReconnect=true");
    dataSource.setUsername("######");
    dataSource.setPassword("########");
    return dataSource;
 }

实体:

@Repository
public interface BlockedEmailRepository extends 
CrudRepository<BlockedEmail, Long> {

List<BlockedEmail> findByUsernameAndEmailId(String username, String 
emailId);

}

1 个答案:

答案 0 :(得分:0)

由于以下冲突,我遇到了这个问题:

  1. Apache James使用OpenJPA 2.4.2作为其持久性提供程序。
  2. 但是在我的代码中,我使用Hibernate作为持久性提供程序。
  3. 我们试图使用Spring-Data-JPA,而James并未使用Spring Data。

因此,存在冲突。为了解决该问题,我们扩展了相同的OpenJPA配置/实现以应用于我们要保留的数据,并使用了James使用的相同的Persistence单元来解决了问题。