我正在尝试将spring-data-jpa升级到其最新版本,即2.1.2.RELEASE。但是在tomcat中部署项目时遇到了一个问题。
export BAD_SERVICES=$(get_bad_services.sh)
ansible-playbook fix_bad_services.yml -e bad_services=$BAD_SERVICES
我在互联网上进行了搜索,但找不到任何解决方案。 我最近升级到Spring 5.1.2。 这是我用于jpa的依赖项
[INFO ] 2018-11-14 13:07:52.454 [localhost-startStop-1] LocalContainerEntityManagerFactoryBean - Initialized JPA EntityManagerFactory for persistence unit 'default'
[WARN ] 2018-11-14 13:07:53.317 [localhost-startStop-1] XmlWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'accountRestController': Unsatisfied dependency expressed through field 'pgTransactionService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'PGTransactionServiceImpl': Unsatisfied dependency expressed through field 'onlineTxnLogDao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'onlineTxnLogDao': Unsatisfied dependency expressed through field 'onlineTxnLogRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'onlineTxnLogRepository': Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.jpa.repository.support.QuerydslJpaPredicateExecutor]: Constructor threw exception; nested exception is java.lang.ClassCastException: com.chat.dao.model.QPGOnlineTxnLog cannot be cast to com.querydsl.core.types.EntityPath
[INFO ] 2018-11-14 13:07:53.318 [localhost-startStop-1] LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'default'
[ERROR] 2018-11-14 13:07:53.332 [localhost-startStop-1] ContextLoader - Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'accountRestController': Unsatisfied dependency expressed through field 'pgTransactionService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'PGTransactionServiceImpl': Unsatisfied dependency expressed through field 'onlineTxnLogDao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'onlineTxnLogDao': Unsatisfied dependency expressed through field 'onlineTxnLogRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'onlineTxnLogRepository': Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.jpa.repository.support.QuerydslJpaPredicateExecutor]: Constructor threw exception; nested exception is java.lang.ClassCastException: com.chat.dao.model.QPGOnlineTxnLog cannot be cast to com.querydsl.core.types.EntityPath
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:374) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1378) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:575) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:846) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:400) ~[spring-web-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:291) [spring-web-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103) [spring-web-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4813) [catalina.jar:8.0.35]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5272) [catalina.jar:8.0.35]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147) [catalina.jar:8.0.35]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407) [catalina.jar:8.0.35]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397) [catalina.jar:8.0.35]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_151]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_151]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_151]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_151]
这是我正在使用的xml配置文件
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-core</artifactId>
<version>3.7.4</version>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>3.7.4</version>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>3.7.4</version>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>4.1.3</version>
</dependency>
我在这里做错了什么。我想念什么吗? 在此之前,我遇到了一个Maven构建问题“无法访问OrderSpecifier”,并找到了必须添加jpa依赖项的解决方案here。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-4.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/oxm
http://www.springframework.org/schema/oxm/spring-oxm-4.1.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-4.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd ">
<jee:jndi-lookup id="chatSysConfigId"
jndi-name="java:comp/env/java/chatSysConfig" resource-ref="true" />
<!-- bean declaration to read properties file -->
<bean id="chatProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location" ref="chatSysConfigId" />
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<ref bean="chatSysConfigId" />
</list>
</property>
</bean>
<context:annotation-config />
<context:component-scan base-package="com.chat" />
<mvc:annotation-driven />
<jpa:repositories base-package="com.chat.dao.repository" />
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource"
destroy-method="close">
<property name="driverClassName" value="${chat.db.driverClass}" />
<property name="jdbcUrl" value="${chat.db.jdbcUrl}" />
<property name="username" value="${chat.db.user}" />
<property name="password" value="${chat.db.password}" />
<property name="maximumPoolSize" value="${chat.db.maxPoolSize}" />
<property name="minimumIdle" value="${chat.db.minPoolSize}" />
<property name="idleTimeout" value="${chat.db.idleConnectionTestPeriod}" />
<property name="connectionTimeout" value="${chat.db.connectionTimeout}" />
<property name="maxLifetime" value="${chat.db.maxLifetime}" />
<property name="leakDetectionThreshold" value="${chat.db.leakDetectionThreshold}" />
<property name="poolName" value="${chat.db.poolName}" />
<property name="dataSourceProperties" ref="dataSourcePropertiesId" />
</bean>
<util:properties id="dataSourcePropertiesId">
<prop key="cachePrepStmts">${chat.db.cachePrepStmts}</prop>
<prop key="prepStmtCacheSize">${chat.db.prepStmtCacheSize}</prop>
<prop key="prepStmtCacheSqlLimit">${chat.db.prepStmtCacheSqlLimit}</prop>
<prop key="useServerPrepStmts">${chat.db.useServerPrepStmts}</prop>
</util:properties>
<!-- Transaction Manager -->
<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="jpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="generateDdl" value="false" />
<property name="database" value="${chat.db.database}" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
<property name="jpaProperties">
<props>
<prop key="hibernate.id.new_generator_mappings">false</prop>
</props>
</property>
<!-- spring based scanning for entity classes -->
<property name="packagesToScan" value="com.chat.dao" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
</beans>
哪个解决了构建问题,但现在我在部署时遇到了所有其他问题。