注入自动装配的依赖项失败,并且属性transactionManager是必需的

时间:2017-11-07 19:54:33

标签: java spring hibernate autowired

这是使用spring将钱从一个帐户转移到另一个帐户的应用程序,我收到错误“注入自动连接的依赖项失败”。我得到了MySQL的执行但没有使用Oracle,我认为这可能是Oracle版本的问题,我尝试在不同版本的Oracle上执行,但错误是相同的。

Nov 07, 2017 1:24:10 PM org.springframework.test.context.support.AbstractTestContextBootstrapper getDefaultTestExecutionListenerClassNames
    INFO: Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
    Nov 07, 2017 1:24:10 PM org.springframework.test.context.support.AbstractTestContextBootstrapper instantiateListeners
    INFO: Could not instantiate TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [javax/servlet/ServletContext]
    Nov 07, 2017 1:24:10 PM org.springframework.test.context.support.AbstractTestContextBootstrapper getTestExecutionListeners
    INFO: Using TestExecutionListeners: [org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@1fd17e3, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@dbc5d3, org.springframework.test.context.support.DirtiesContextTestExecutionListener@a9e816, org.springframework.test.context.transaction.TransactionalTestExecutionListener@1d99928, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@34d63f]
    Nov 07, 2017 1:24:10 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from class path resource [config.xml]
    Nov 07, 2017 1:24:11 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
    INFO: Refreshing org.springframework.context.support.GenericApplicationContext@1829d67: startup date [Tue Nov 07 13:24:11 CST 2017]; root of context hierarchy
    Nov 07, 2017 1:24:12 PM org.hibernate.cfg.Environment <clinit>
    INFO: Hibernate 3.5.6-Final
    Nov 07, 2017 1:24:12 PM org.hibernate.cfg.Environment <clinit>
    INFO: hibernate.properties not found
    Nov 07, 2017 1:24:12 PM org.hibernate.cfg.Environment buildBytecodeProvider
    INFO: Bytecode provider name : javassist
    Nov 07, 2017 1:24:12 PM org.hibernate.cfg.Environment <clinit>
    INFO: using JDK 1.4 java.sql.Timestamp handling
    Nov 07, 2017 1:24:12 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
    INFO: Mapping class: pojos.Withdraw -> WITHDRAW
    Nov 07, 2017 1:24:12 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
    INFO: Mapping class: pojos.Depostie -> DEPOSITE
    Nov 07, 2017 1:24:12 PM org.springframework.orm.hibernate3.LocalSessionFactoryBean buildSessionFactory
    INFO: Building new Hibernate SessionFactory
    Nov 07, 2017 1:24:12 PM org.hibernate.connection.ConnectionProviderFactory initializeConnectionProviderFromConfig
    INFO: Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: RDBMS: Oracle, version: Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: JDBC driver: Oracle JDBC driver, version: 11.1.0.7.0-Production
    Nov 07, 2017 1:24:15 PM org.hibernate.dialect.Dialect <init>
    INFO: Using dialect: org.hibernate.dialect.Oracle10gDialect
    Nov 07, 2017 1:24:15 PM org.hibernate.engine.jdbc.JdbcSupportLoader useContextualLobCreation
    INFO: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
    Nov 07, 2017 1:24:15 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
    INFO: Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
    Nov 07, 2017 1:24:15 PM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
    INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Automatic flush during beforeCompletion(): disabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Automatic session close at end of transaction: disabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: JDBC batch size: 15
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: JDBC batch updates for versioned data: disabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Scrollable result sets: enabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: JDBC3 getGeneratedKeys(): disabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Connection release mode: auto
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Default batch fetch size: 1
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Generate SQL with comments: enabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Order SQL updates by primary key: disabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Order SQL inserts for batching: disabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
    INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
    Nov 07, 2017 1:24:15 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
    INFO: Using ASTQueryTranslatorFactory
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Query language substitutions: {}
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: JPA-QL strict compliance: disabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Second-level cache: enabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Query cache: disabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory createRegionFactory
    INFO: Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Optimize cache for minimal puts: disabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Structured second-level cache entries: disabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Echoing all SQL to stdout
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Statistics: disabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Deleted entity synthetic identifier rollback: disabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Default entity-mode: pojo
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Named query checking : enabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Check Nullability in Core (should be disabled when Bean Validation is on): enabled
    Nov 07, 2017 1:24:15 PM org.hibernate.impl.SessionFactoryImpl <init>
    INFO: building session factory
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
    INFO: Mapping class: pojos.Withdraw -> WITHDRAW
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
    INFO: Mapping class: pojos.Depostie -> DEPOSITE
    Nov 07, 2017 1:24:15 PM org.springframework.orm.hibernate3.LocalSessionFactoryBean buildSessionFactory
    INFO: Building new Hibernate SessionFactory
    Nov 07, 2017 1:24:15 PM org.hibernate.connection.ConnectionProviderFactory initializeConnectionProviderFromConfig
    INFO: Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: RDBMS: Oracle, version: Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: JDBC driver: Oracle JDBC driver, version: 11.1.0.7.0-Production
    Nov 07, 2017 1:24:15 PM org.hibernate.dialect.Dialect <init>
    INFO: Using dialect: org.hibernate.dialect.Oracle10gDialect
    Nov 07, 2017 1:24:15 PM org.hibernate.engine.jdbc.JdbcSupportLoader useContextualLobCreation
    INFO: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
    Nov 07, 2017 1:24:15 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
    INFO: Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
    Nov 07, 2017 1:24:15 PM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
    INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Automatic flush during beforeCompletion(): disabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Automatic session close at end of transaction: disabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: JDBC batch size: 15
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: JDBC batch updates for versioned data: disabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Scrollable result sets: enabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: JDBC3 getGeneratedKeys(): disabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Connection release mode: auto
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Default batch fetch size: 1
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Generate SQL with comments: enabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Order SQL updates by primary key: disabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Order SQL inserts for batching: disabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
    INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
    Nov 07, 2017 1:24:15 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
    INFO: Using ASTQueryTranslatorFactory
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Query language substitutions: {}
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: JPA-QL strict compliance: disabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Second-level cache: enabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Query cache: disabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory createRegionFactory
    INFO: Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Optimize cache for minimal puts: disabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Structured second-level cache entries: disabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Echoing all SQL to stdout
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Statistics: disabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Deleted entity synthetic identifier rollback: disabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Default entity-mode: pojo
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Named query checking : enabled
    Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Check Nullability in Core (should be disabled when Bean Validation is on): enabled
    Nov 07, 2017 1:24:15 PM org.hibernate.impl.SessionFactoryImpl <init>
    INFO: building session factory
    Nov 07, 2017 1:24:15 PM org.springframework.context.support.AbstractApplicationContext refresh
    WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transferMoney': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.transaction.support.TransactionTemplate tx.TransferMoney.txTemplate; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.support.TransactionTemplate#0' defined in class path resource [config.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'transactionManager' is required
    Nov 07, 2017 1:24:15 PM org.springframework.test.context.TestContextManager prepareTestInstance
    SEVERE: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@dbc5d3] to prepare test instance [test.TxTest@1d6ca49]
    java.lang.IllegalStateException: Failed to load ApplicationContext
        at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
        at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
        at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
        at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
        at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:228)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:230)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:249)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
        at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
        at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transferMoney': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.transaction.support.TransactionTemplate tx.TransferMoney.txTemplate; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.support.TransactionTemplate#0' defined in class path resource [config.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'transactionManager' is required
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
        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.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:125)
        at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
        at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:109)
        at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:261)
        at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
        at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
        ... 25 more
    Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.transaction.support.TransactionTemplate tx.TransferMoney.txTemplate; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.support.TransactionTemplate#0' defined in class path resource [config.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'transactionManager' is required
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
        at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
        ... 41 more
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.support.TransactionTemplate#0' defined in class path resource [config.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'transactionManager' is required
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
        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.findAutowireCandidates(DefaultListableBeanFactory.java:1192)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
        ... 43 more
    Caused by: java.lang.IllegalArgumentException: Property 'transactionManager' is required
        at org.springframework.transaction.support.TransactionTemplate.afterPropertiesSet(TransactionTemplate.java:119)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
        ... 53 more

这是配置文件

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd  
                        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">
    <context:component-scan base-package="tx daoimpl" />
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
        <property name="url" value="jdbc:oracle:thin:@localhost:1521:xe" />
        <property name="username" value="system" />
        <property name="password" value="system" />
        <property name="initialSize" value="5" />
        <property name="maxActive" value="10" />
    </bean>
    <!-- Mixing autowiring with explicit wiring -->
    <bean class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
        autowire="byName">
        <!-- <property name="dataSource" ref="dataSource" /> -->
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.use_sql_comments">true</prop>
                <prop key="hibernate.transaction.factory_class">
                    org.hibernate.transaction.JDBCTransactionFactory
                </prop>
            </props>
        </property>
        <property name="mappingResources">
            <array>
                <value>withdraw.hbm.xml</value>
                <value>deposit.hbm.xml</value>
            </array>
        </property>
    </bean>
    <bean class="org.springframework.transaction.support.TransactionTemplate"
        autowire="constructor" />

    <bean class="org.springframework.orm.hibernate3.HibernateTransactionManager"
        autowire="constructor" />

    <bean class="org.springframework.orm.hibernate3.HibernateTemplate"
        autowire="constructor" />


</beans>

这是服务代码

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;

import daoimpl.DepositImpl;
import daoimpl.WithdrawdaoImpl;
import pojos.Deposit;
import pojos.Withdraw;

@Service("transferMoney")
public class TransferMoney implements ITransfer{

    @Autowired
    private TransactionTemplate txTemplate;
    @Autowired
    private WithdrawdaoImpl withdrawdao;
    @Autowired
    private DepositImpl depositdao;

    public void transfer(int fromAcc, int toAcc) {
        txTemplate.execute(new TransactionCallback(){
            public Object doInTransaction(TransactionStatus arg0){
                try{
                    Withdraw w=withdrawdao.read(fromAcc);
                    w.setAmount(w.getAmount() - 100);
                    withdrawdao.update(w);

                    Deposit d=depositdao.read(toAcc);
                    d.setAmount(d.getAmount() + 100);
                    depositdao.update(d);

                }catch(Exception e){
                    e.printStackTrace();
                    arg0.setRollbackOnly();
                }
                return null;
            }
        });

    }

}

1 个答案:

答案 0 :(得分:0)

您可以尝试两种选择。首先将id="transactionManager"添加到您的HibernateTransactionManager bean定义中。

如果这比尝试以下配置没有帮助:

 <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource"></property>
</bean>

<!-- Instance of transaction template -->
<bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
  <property name="transactionManager" ref="transactionManager"></property>
</bean>