0

NoSuchBeanDefinitionException - 「'transactionManager' という名前の Bean が定義されていません」が構成で発生します。通常の webapp 起動の場合、私の構成は実行されています。

JUnit クラス

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({ TransactionalTestExecutionListener.class, DependencyInjectionTestExecutionListener.class })
@ContextConfiguration(locations = {"classpath:**/applicationContext.xml", "classpath:**/datasource-config.xml"}) //, 
@TransactionConfiguration(defaultRollback = true)
@Transactional
public class TestTripService {

TripService tripService;

@Test
public void addTrip() { 
  .
  .
  .

アプリケーションコンテキスト.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans .......
spring-context-3.0.xsd">
<import resource="datasource-config.xml" />
<import resource="webflow-config.xml" />
<import resource="security-config.xml" />


<context:annotation-config/>
<context:component-scan base-package="de.wiegand.mytransport" />

<!-- DAO declarations -->
<bean id="userDao" class="de.wiegand.mytransport.dao.UserJpaDao" />
<bean id="shippingAgencyDao" class="de.wiegand.mytransport.dao.ShippingAgencyJplDao" />

<!-- Services declarations -->
<bean id="userService" class="de.wiegand.mytransport.services.impl.UserServiceImpl">
    <property name="userDao" ref="userDao" />
    <property name="shippingAgencyDao" ref="shippingAgencyDao" />
</bean>

<bean id="userAuthenticationProviderService"
    class="de.wiegand.mytransport.services.impl.UserAuthenticationProviderServiceImpl">
    <property name="authenticationManager" ref="authenticationManager" />
</bean>

<bean id="tripService" class="de.wiegand.mytransport.services.impl.TripServiceImpl" />

<bean id="schedulerTask" class="org.springframework.scheduling.timer.MethodInvokingTimerTaskFactoryBean">
    <property name="targetObject" ref="postCodeManager" />
    <property name="targetMethod" value="init" />
</bean>

<bean id="postCodeManager" class="de.wiegand.mytransport.postcodeservice.PostCodeManager" />

<bean id="timerTask" class="org.springframework.scheduling.timer.ScheduledTimerTask">
    <property name="timerTask" ref="schedulerTask" />
    <property name="delay" value="1000" />
</bean>

<bean class="org.springframework.scheduling.timer.TimerFactoryBean">
    <property name="scheduledTimerTasks">
        <list>
            <ref local="timerTask" />
        </list>
    </property>
</bean>

datasource-config.xml

<?xml version="1.0" encoding="UTF-8"?>

<context:property-placeholder location="classpath:datasource.properties" />

<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">

    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost:3306/test2" />
    <property name="username" value="root" />
    <property name="password" value="" />
</bean>

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="showSql" value="true" />
            <property name="generateDdl" value="true" />
            <property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect" />
        </bean>
    </property>

    <property name="dataSource" ref="dataSource" />
</bean>

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

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

<bean
    class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

お時間いただきありがとうございます。

4

1 に答える 1

0

以下の注釈をテスト クラスに追加します。

@TransactionConfiguration(transactionManager="txManager")

ここtxManagerで、Spring 構成ファイルで定義された TranscationManager 名です。

于 2014-11-27T08:27:44.553 に答える