本文介绍了没有定义名为'transactionManager'的bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



 < bean id =liveEntityManagerFactory 

我已经配置了两个持久化单元,实体管理器的设置如下所示:
class =org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
p:dataSource-ref =LiveDataSource>

< property name =persistenceUnitNamevalue =LivePersistenceUnit/>
< / bean>

< bean id =archiveEntityManagerFactory
class =org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
p:dataSource-ref =ArchiveDataSource>

< property name =persistenceUnitNamevalue =ArchivePersistenceUnit/>
< / bean>

然后我将事务管理器配置为

<$
:entityManagerFactory-ref =liveEntityManagerFactory/> p $ p $ < bean id =LiveTransactionManager
class =org.springframework.orm.jpa.JpaTransactionManager

< bean id =ArchiveTransactionManager
class =org.springframework.orm.jpa.JpaTransactionManager
p:entityManagerFactory-ref =archiveEntityManagerFactory/>

我原本只配置了一个,它被称为transactionManager。添加一个额外的持久单元似乎会产生一个错误。
有一件事我不明白,如果我配置了两个持久单元(每个单独的数据库),我是否还需要为每个数据源配置单独的实体管理器和事务管理器?



我得到的错误如下所示:(我搜索了所有的文件,并且找不到任何有transactionManager引用的地方)

  org.springframework.ws.soap.client.SoapFaultClientException:没有名为'transactionManager'的bean在org.springframework.ws中被定义为
。在org.springframework.ws.client.core.WebServiceTemplate.handleFault soap.client.core.SoapFaultMessageResolver.resolveFault(SoapFaultMessageResolver.java:37)
(WebServiceTemplate.java:774)
。在org.springframework。在org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:600)
(WebServiceTemplate.java:537)
。在org.springframework。 ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:384)
在org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:378)在org.s
pringframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:370)
处sun.reflect.NativeMethodAccessorImpl com.ws.client.SoapTest.testFail(SoapTest.java:140)
。 invoke0(本机方法)处是java sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

。 lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall(FrameworkMethod.java:44)
org.junit.internal.runners .model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements .InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.springframework.test.context .junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
在org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
在org.springframework.test .context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
在org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
。在组织.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
在org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
在org.junit.runners .ParentRunner.runChildren(ParentRunner.java:180)
at org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:41)
at org.junit.runners.ParentRunner $ 1.evaluate(ParentRunner .java:173)
在org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
在org.springframework.test.co ntext.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
处org.springframework org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
。 test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
处org.springframework.test org.junit.runners.ParentRunner.run(ParentRunner.java:220)
。 context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
在org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
。在org.apache.maven。 surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
处sun.reflect.NativeMethodAccessorImpl org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
。 invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImp l.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray( ReflectionUtils.java:164)
在org.apache.maven.surefire.booter.ProviderFactory $ ProviderProxy.invoke(ProviderFactory.java:110)
在org.apache.maven.surefire.booter.SurefireStarter。 invokeProvider(SurefireStarter.java:175)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
at org.apache.maven.surefire.booter.ForkedBooter。 main(ForkedBooter.java:68)

我使用Spring和Jpa / Hibernate。



谢谢

解决方案

transaction-manager属性的默认值是交易经理。在你的情况下,你应该指定每个方法或服务使用哪个事务管理器: b @Transactional(value =LiveTransactionManager)
class someClass ...



  @Transactional(value =ArchiveTransactionManager)
public void someMethod


I have configured two persistent units with the entity managers set up as show below:

<bean id="liveEntityManagerFactory" 
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
          p:dataSource-ref="LiveDataSource">          

          <property name="persistenceUnitName" value="LivePersistenceUnit" />
    </bean>

    <bean id="archiveEntityManagerFactory" 
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
          p:dataSource-ref="ArchiveDataSource">          

          <property name="persistenceUnitName" value="ArchivePersistenceUnit" />
    </bean>

I then configured the transaction managers as

 <bean id="LiveTransactionManager"
          class="org.springframework.orm.jpa.JpaTransactionManager"
          p:entityManagerFactory-ref="liveEntityManagerFactory"/>

    <bean id="ArchiveTransactionManager"
          class="org.springframework.orm.jpa.JpaTransactionManager"
          p:entityManagerFactory-ref="archiveEntityManagerFactory"/>  

I originally had just one configured and it was called "transactionManager". Addint an additional persistent unit seems to generate an error. One thing i dont understand, if i configured two persistent units (each for a separate database) do i also need to configure an individual entity manager and a transaction manager for each datasource?

The error that i get is shown below: (I have search all file and i cant find anywhere where there is a reference for "transactionManager")

org.springframework.ws.soap.client.SoapFaultClientException: No bean named 'transactionManager' is defined
    at org.springframework.ws.soap.client.core.SoapFaultMessageResolver.resolveFault(SoapFaultMessageResolver.java:37)
    at org.springframework.ws.client.core.WebServiceTemplate.handleFault(WebServiceTemplate.java:774)
    at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:600)
    at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:537)
    at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:384)
    at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:378)
    at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:370)
    at com.ws.client.SoapTest.testFail(SoapTest.java:140)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
    at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)

I am using Spring with Jpa/Hibernate.

Thanks

解决方案

The default value for the transaction-manager attribute is transaction-manager. In your case, you should specify which transaction manager you want to use per method or service like this:

@Service
@Transactional(value="LiveTransactionManager") 
class someClass...

or

@Transactional(value="ArchiveTransactionManager") 
public void someMethod

这篇关于没有定义名为'transactionManager'的bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 21:49