spring - 将 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
解决方案
这通过从基于 Java 的 bean 配置转移到基于 XML 的配置来解决。
推荐阅读
- facebook - 以用户身份向另一个用户发送消息
- java - OKTA 多因素身份验证 + Java + RestAssured:/authorize API 调用将我引导回登录页面
- javascript - 如果使用 document.documentElement.scrollTop 向下滚动页面会晃动
- sql - 如何进行选择以将记录相对于彼此放在另一个下方
- xamarin - 如何使用渲染器更改 Android 选项卡的背景颜色,同时使用自定义渲染器添加一些填充
- arduino - 如何让nodemcu自动连接强wifi信号
- laravel - Laravel如何从数据库中获取不同的数据?
- android - 在 C++ 中为 Android 应用程序编码 ASCII
- java - 从 CSV 到数组的字符串(Java)
- javascript - 为什么只有我的第一个路由器渲染组件?第二个路由器没有渲染