首页 > 解决方案 > 将 Spring Data JPA 与 Spring JPA 一起使用时的问题

问题描述

问题
- 收到战争文件部署错误。获取运行时异常。在一些附加信息之后提到了错误详细信息。

一些背景 -
1) 功能与 Spring JPA 库一起使用。当它迁移到 Spring Data JPA 时,它失败了。
2) 我正在使用基于 Spring Java 注释的配置来加载 bean。
3) 我有 2 个数据源。其中之一是使用数据源访问可以使用不同的 jar 文件检索的数据。此 jar 文件使用 Spring Data JPA v 1.10.2.RELEASE
4) 我们的应用程序使用 Spring 4.2.6 版本

执行 -

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = 
"com.security.repository", entityManagerFactoryRef = 
"entityManager")
public class PersistenceConfig {

    @Bean(name = "dataSource")
    public DataSource dataSource() throws NamingException {
        return (DataSource) jndidataSource().getObject();
    }

    @Bean
    public JndiObjectFactoryBean jndiDataSource() {
     JndiObjectFactoryBean jndiObjectFactoryBean = new 
     JndiObjectFactoryBean();
     jndiObjectFactoryBean.setJndiName("dbDataSourceName");
     jndiObjectFactoryBean.setExpectedType(DataSource.class);
     return jndiObjectFactoryBean;
   }

     @Bean(name = "entityManager")
     public LocalContainerEntityManagerFactoryBean entityManagerObj() throws 
     NamingException {
    LocalContainerEntityManagerFactoryBean emf = new 
      LocalContainerEntityManagerFactoryBean();
    emf.setJtaDataSource(jndiDataSource());
    emf.setPersistenceUnitName("PersistenceUnit");
    emf.setPackagesToScan("com.security.entity");
    emf.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());
    emf.setPersistenceProvider(new PersistenceProvider());
    emf.setJpaProperties(getJPAProperties());
    return emf;
  }

  private Properties getJPAProperties() {
    Properties jpaProperties = new Properties();
    jpaProperties.put("eclipselink.weaving", "false");
    jpaProperties.put("eclipselink.jpa.uppercase-column-names", "true");
    jpaProperties.put("eclipselink.logging.level", "SEVERE");
    jpaProperties.put("eclipselink.logging.parameters", "true");
    jpaProperties.put("eclipselink.query-results-cache", "false");
    jpaProperties.put("eclipselink.cache.shared.default", "false");
    jpaProperties.put("eclipselink.cache.type.default ", "NONE");
    jpaProperties.put("eclipselink.logging.level.sql", "SEVERE");
    jpaProperties.put("eclipselink.jdbc.batch-writing", "JDBC");
    jpaProperties.put("eclipselink.jdbc.batch-writing.size", "100");
    return jpaProperties;
 }
}

当使用上述配置部署应用程序时,它会给我以下错误。不确定缺少什么或不正确。因为它使用的是使用 Spring JPA 而不是 Spring Data JPA 实现的库。请建议——

org.springframework.beans.factory.UnsatisfiedDependencyException: Error 
creating bean with name 'jpaContext': Unsatisfied dependency expressed 
through constructor argument with index 0 of type [java.util.Set]: Error 
creating bean with name 
'org.springframework.orm.jpa.SharedEntityManagerCreator#2': Unsatisfied 
dependency expressed through constructor argument with index 0 of type 
[javax.persistence.EntityManagerFactory]: Could not convert factory method 
argument value of type [weblogic.jdbc.common.internal.RmiDataSource] to 
required type [javax.persistence.EntityManagerFactory]: Failed to convert 
value of type [weblogic.jdbc.common.internal.RmiDataSource] to required type 
[javax.persistence.EntityManagerFactory]; nested exception is 
java.lang.IllegalStateException: Cannot convert value of type 
[weblogic.jdbc.common.internal.RmiDataSource] to required type 
[javax.persistence.EntityManagerFactory]: no matching editors or conversion 
strategy found; nested exception is 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error 
creating bean with name 
'org.springframework.orm.jpa.SharedEntityManagerCreator#2': Unsatisfied 
dependency expressed through constructor argument with index 0 of type 
[javax.persistence.EntityManagerFactory]: Could not convert factory method 
argument value of type [weblogic.jdbc.common.internal.RmiDataSource] to 
required type [javax.persistence.EntityManagerFactory]: Failed to convert 
value of type [weblogic.jdbc.common.internal.RmiDataSource] to required type 
[javax.persistence.EntityManagerFactory]; nested exception is 
java.lang.IllegalStateException: Cannot convert value of type 
[weblogic.jdbc.common.internal.RmiDataSource] to required type 
[javax.persistence.EntityManagerFactory]: no matching editors or conversion 
strategy found

标签: springspring-data-jpaweblogic12cspring-orm

解决方案


这通过从基于 Java 的 bean 配置转移到基于 XML 的配置来解决。


推荐阅读