gpt4 book ai didi

java - spring-data-jpa 1.9.4 升级到 1.10.2 后出现问题

转载 作者:行者123 更新时间:2023-11-30 07:10:51 25 4
gpt4 key购买 nike

在 Wildfly 服务器中将 spring-data-jpa 从 1.9.4 升级到 1.10.2 后,我遇到了一些 bean 创建问题。以下是我的异常堆栈跟踪

Caused by: 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#1': Unsatisfied dependency expressed through constructor argument with index 0 of type [javax.persistence.EntityManagerFactory]: Could not convert factory method argument value of type [org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory] to required type [javax.persistence.EntityManagerFactory]: Failed to convert value of type [org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory] to required type [javax.persistence.EntityManagerFactory]; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory] 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#1': Unsatisfied dependency expressed through constructor argument with index 0 of type [javax.persistence.EntityManagerFactory]: Could not convert factory method argument value of type [org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory] to required type [javax.persistence.EntityManagerFactory]: Failed to convert value of type [org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory] to required type [javax.persistence.EntityManagerFactory]; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory] to required type [javax.persistence.EntityManagerFactory]: no matching editors or conversion strategy found
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.orm.jpa.SharedEntityManagerCreator#1': Unsatisfied dependency expressed through constructor argument with index 0 of type [javax.persistence.EntityManagerFactory]: Could not convert factory method argument value of type [org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory] to required type [javax.persistence.EntityManagerFactory]: Failed to convert value of type [org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory] to required type [javax.persistence.EntityManagerFactory]; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory] to required type [javax.persistence.EntityManagerFactory]: no matching editors or conversion strategy found
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:185)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1143)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1046)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
... 28 more

以下是我的EntityManagerFactory和Spring Data Jpa存储库的@Configuration

@Configuration
@EnableTransactionManagement(proxyTargetClass = true)
public class TransactionConfiguration {

@Bean
public JndiObjectFactoryBean dataSource() throws IllegalArgumentException {
final JndiObjectFactoryBean dataSource = new JndiObjectFactoryBean();
dataSource.setExpectedType(DataSource.class);
dataSource.setJndiName(environment.getProperty("default.jdbc.jndi.dataSource"));
return dataSource;
}

@Bean
public PlatformTransactionManager transactionManager() {
return new JtaTransactionManager();
}

@Bean
public EntityManagerFactory entityManagerFactory() {
final LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();
entityManagerFactory.setJtaDataSource(dataSource());
entityManagerFactory.setPersistenceUnitName("MyPersistenceUnit");
entityManagerFactory.setPackagesToScan(new String[] { "org.mycom.**.entity" });
entityManagerFactory.setJpaVendorAdapter(jpaVendorAdaper());
entityManagerFactory.setJpaPropertyMap(additionalProperties());
entityManagerFactory.setValidationMode(ValidationMode.NONE);
entityManagerFactory.setSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE);
ClasspathScanningPersistenceUnitPostProcessor hbmScanner = new ClasspathScanningPersistenceUnitPostProcessor("com.mycomp");
hbmScanner.setMappingFileNamePattern("**/*hbm.xml");
entityManagerFactory.setPersistenceUnitPostProcessors(hbmScanner);
entityManagerFactory.afterPropertiesSet();
return entityManagerFactory.getObject();
}
}

我的存储库配置如下

@Configuration 
@EnableJpaRepositories(basePackages="org.mycom.**.repository",
repositoryFactoryBeanClass=EnversRevisionRepositoryFactoryBean.class)
@EnableJpaAuditing
public class RepositoryConfiguration {

@Autowired
private SecurityUtils securityUtils;

@Bean
@Profile("production")
public AuditorAware<User> springSecurityAwareAuditor() {
return () -> securityUtils.getCurrentUser();
}

}

最佳答案

这是一个 bug in Spring Data JPA ,已针对 Ingalls RC1 和 Hopper SR3(包括 Spring Boot 1.4.1)进行了修复。

解决方法是在 XML 配置文件中声明 JNDI 对象并显式设置 expected-type 属性。

关于java - spring-data-jpa 1.9.4 升级到 1.10.2 后出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39269810/

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