Spring:没有配置任何事务管理器

Jip*_*ppe 2 spring hibernate transactions

我一直在努力解决这个问题,并没有看到解决方案.希望有人能帮助我.

我配置了HibernateTransactionManager.但是,我在日志文件中看到以下消息:

DEBUG [http-8080-1] AnnotationTransactionAttributeSource.getTransactionAttribute(107)| 使用属性[PROPAGATION_REQUIRED,ISOLATION_DEFAULT,-nl.forestfields.picnic.domain.model.exception.IllegalCostException]添加事务方法[cashIn]

DEBUG [http-8080-1] AnnotationTransactionAspect.createTransactionIfNecessary(267)| 跳过事务连接点[nl.forestfields.picnic.view.controller.ShoppingListController.cashIn],因为没有配置事务管理器

此外,如果发生异常,则不会回滚事务.

这是我的配置:

野餐servlet.xml中:

  <beans>

    <context:component-scan base-package="picnic" />
    <context:annotation-config />

    <tx:annotation-driven />
    .
    .
    .
Run Code Online (Sandbox Code Playgroud)

野餐上下文db.xml:

<bean class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" id="sessionFactory">

    <property name="configLocation" value="classpath:hibernate.cfg.xml" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
        </props>
    </property>
    <property name="dataSource" ref="dataSource" />
</bean>

<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
    <property name="sessionFactory" ref="sessionFactory" />
 </bean>

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName">
        <value>${hibernate.connection.driver_class}</value>
    </property>
    <property name="url">
        <value>${hibernate.connection.url}</value>
    </property>
    <property name="username">
        <value>${hibernate.connection.username}</value>
    </property>
    <property name="password">
        <value>${hibernate.connection.password}</value>
    </property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>
Run Code Online (Sandbox Code Playgroud)

应该在事务中执行的代码:

@Transactional(rollbackFor=IllegalCostException.class)
public ModelAndView cashIn(@RequestParam final Long id) throws IllegalCostException, llegalOrderStateException, IllegalShoppingListStateException {

  final ShoppingList shoppingList = shoppingListRepository.getById(id);
  shoppingList.cashIn();
  shoppingListRepository.add(shoppingList);

  return new ModelAndView(...);
}
Run Code Online (Sandbox Code Playgroud)

有谁能看到这个问题?

干杯,Jippe

Jer*_*ese 6

尝试改变

<tx:annotation-driven />
       to
<tx:annotation-driven transaction-manager="transactionManager" />
Run Code Online (Sandbox Code Playgroud)

在这里找不到任何其他问题.