简体   繁体   English

Bean属性“transactionManagerBeanName”不可写或具有无效的setter方法

[英]Bean property 'transactionManagerBeanName' is not writable or has an invalid setter method

I am trying to configure Spring3 + JPA using Hibernate, but I am getting an exception while spring tries to create a Bean called TransactionInterceptor, the exception is attached. 我正在尝试使用Hibernate配置Spring3 + JPA,但是我在Spring尝试创建一个名为TransactionInterceptor的Bean时遇到异常,附加了异常。 Any help is welcome. 欢迎任何帮助。 I am sending my app-config.xml, my persistence.xml and the error stack trace below: 我发送的app-config.xml,我的persistence.xml和错误堆栈跟踪如下:

My app-config.xml 我的app-config.xml

    <beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
 xmlns:aop="http://www.springframework.org/schema/aop" 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:task="http://www.springframework.org/schema/task"
 xsi:schemaLocation="
   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
   http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
   http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
   http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">

 <context:component-scan base-package="com.mypackage" />

 <task:annotation-driven executor="myExecutor"
  scheduler="myScheduler" />

 <task:executor id="myExecutor" pool-size="5" />

 <task:scheduler id="myScheduler" pool-size="10" />

 <context:load-time-weaver />

 <bean id="entityManagerFactory"
  class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
  <property name="persistenceUnitName" value="MyPersistenceUnit" />
 </bean>

 <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
  <property name="entityManagerFactory" ref="entityManagerFactory" />
 </bean>
 <bean
  class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

 <tx:annotation-driven transaction-manager="transactionManager" />
</beans>

Here is my persistence.xml 这是我的persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
 xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
 <persistence-unit name="MyPersistenceUnit"
  transaction-type="RESOURCE_LOCAL">

  <!-- org.apache.openjpa.persistence.PersistenceProviderImpl -->
  <provider>org.hibernate.ejb.HibernatePersistence</provider>

  <properties>
   <property name="hibernate.connection.provider_class"
    value="org.hibernate.connection.C3P0ConnectionProvider" />
   <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
   <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
   <property name="hibernate.max_fetch_depth" value="3" />
   <property name="hibernate.query.factory_class"
    value="org.hibernate.hql.classic.ClassicQueryTranslatorFactory" />
   <property name="hibernate.query.substitutions" value="true 1, false 0" />
   <property name="hibernate.show_sql" value="true" />
   <property name="hibernate.hbm2ddl.auto" value="create" />
   <property name="hibernate.default_schema" value="MYDATABASE" />

   <!-- Use the C3P0 connection pool. -->
   <property name="hibernate.c3p0.min_size" value="10" />
   <property name="hibernate.c3p0.max_size" value="25" />
   <property name="hibernate.c3p0.timeout" value="600" />
   <property name="hibernate.c3p0.idle_test_period" value="15" />
   <property name="hibernate.connection.url"
    value="jdbc:mysql://localhost:3306/MYDATABASE?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=utf-8" />
   <property name="hibernate.connection.username" value="root" />
   <property name="hibernate.connection.password" value="root" />

   <property name="hibernate.cache.provider_class"
    value="net.sf.ehcache.hibernate.SingletonEhCacheProvider" />
   <property name="hibernate.cache.use_query_cache" value="true" />
   <property name="hibernate.cache.use_second_level_cache"
    value="true" />
   <property name="hibernate.generate_statistics" value="true" />

  </properties>

 </persistence-unit>
</persistence>

Here is the exception: 这是一个例外:

SEVERE: StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.interceptor.TransactionInterceptor#0': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'transactionManagerBeanName' of bean class [org.springframework.transaction.interceptor.TransactionInterceptor]: Bean property 'transactionManagerBeanName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1361)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
 at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
 at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
 at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)
 at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
 at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
 at javax.servlet.GenericServlet.init(GenericServlet.java:212)
 at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
 at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:809)
 at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:615)
 at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
 at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
 at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
 at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:195)
 at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:159)
 at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:141)
 at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:90)
 at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:417)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
 at com.springsource.insight.collection.tcserver.request.HttpRequestOperationCollectionValve.invoke(HttpRequestOperationCollectionValve.java:60)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
 at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:379)
 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
 at java.lang.Thread.run(Thread.java:637)
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'transactionManagerBeanName' of bean class [org.springframework.transaction.interceptor.TransactionInterceptor]: Bean property 'transactionManagerBeanName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
 at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1038)
 at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:914)
 at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)
 at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1358)
 ... 42 more
Aug 31, 2010 1:04:27 AM org.apache.catalina.core.ApplicationDispatcher invoke

I ran into this problem and (I think) have tracked it down to a dependencies problem. 我遇到了这个问题并且(我认为)已将其追踪到依赖性问题。

I'm using org.springframework/spring-tx/3.0.3.RELEASE for transactions, and I had been trying to use org.springframework/spring-hibernate/1.2.9 for the hibernate bindings. 我正在使用org.springframework / spring-tx / 3.0.3.RELEASE进行事务处理,我一直在尝试使用org.springframework / spring-hibernate / 1.2.9进行hibernate绑定。 This was causing grief (I think) because the JARs contained incompatible versions of the TransactionInterceptor class (according to Eclipse). 这导致了悲痛(我认为),因为JAR包含不兼容的TransactionInterceptor类版本(根据Eclipse)。

Now that I have switched to org.springframework/spring-hibernate3/2.0.8 the problem seems to have gone away. 现在我已经切换到org.springframework / spring-hibernate3 / 2.0.8,问题似乎已经消失了。 There are still two versions of the class, but they appear to be compatible. 该类仍有两个版本,但它们似乎兼容。

UPDATE UPDATE

Actually, the correct module for the hibernate3 support classes for Spring 3.0.x seems to be: 实际上,Spring 3.0.x的hibernate3支持类的正确模块似乎是:

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring-version}</version>
    </dependency>

TransactionInterceptor不包含transactionManagerBeanName的setter,仅用于Transaction Manager实例和事务属性。

Very strange, got a new pom.xml from on example project (spring + jpa) and I could get it working. 很奇怪,从示例项目(spring + jpa)获得了一个新的pom.xml,我可以让它工作。 Seems that some dependency was missing. 似乎缺少一些依赖。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NotWritablePropertyException:Bean属性“ dataSource”不可写或具有无效的setter方法 - NotWritablePropertyException: Bean property 'dataSource' is not writable or has an invalid setter method Bean属性xxxDAO无法写或具有无效的setter方法 - Bean property xxxDAO is not writable or has an invalid setter method Bean属性“ channelIdentifierMap”不可写或具有无效的setter方法 - Bean property 'channelIdentifierMap' is not writable or has an invalid setter method Bean属性“ bagBisDomainService”不可写或具有无效的setter方法 - Bean property 'bagBisDomainService' is not writable or has an invalid setter method 春季:Bean属性不可写或具有无效的setter方法 - Spring: Bean property is not writable or has an invalid setter method Spring Bean属性'xxx'不可写或具有无效的setter方法 - Spring Bean property 'xxx' is not writable or has an invalid setter method Bean 属性“sessionFactory”不可写或具有无效的 setter 方法 - Bean property 'sessionFactory' is not writable or has an invalid setter method bean类的属性&#39;profileManager&#39;无效。 Bean属性“profileManager”不可写或具有无效的setter方法 - Invalid property 'profileManager' of bean class. Bean property 'profileManager' is not writable or has an invalid setter method Bean类的无效属性不可写或无效的setter方法 - Invalid property of bean class is not writable or an invalid setter method 是否可以使Spring忽略不可写或具有无效setter方法的bean属性 - Is it possible to make Spring ignore a bean property that is not writable or has an invalid setter method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM