我是否收到“java.lang.IllegalStateException:No TransactionalEventListener annotation”?

时间:2017-06-28 16:38:03

标签: spring transactions listener spring-transactions spring-4

我正在使用Spring 4.3.8.RELEASE和Hibernate 5.1.5.Final。我希望在另一个事务完成后执行一个方法。该交易定义如下

@Service("organizationService")
@Transactional
public class OrganizationServiceImpl implements OrganizationService, ApplicationEventPublisherAware
{

    private ApplicationEventPublisher publisher;

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher publisher) 
    {
        this.publisher = publisher;
    }

    @Override
    public void save(Organization organization)
    {
    ...

        // sync data with ThirdParty but only if something has definitelychanged on the SB
        // side, in which case we want to send ThirdParty an update.
        if (!hasSameAttributes)
        {
            publisher.publishEvent(new ThirdPartyOrganizationEvent(organization.getId()));
        }   // if
    }   // save

所以这是我想在上述事务完成后执行的方法......

@Service
public class ThirdPartyAPIServiceImpl implements ThirdPartyAPIService 
{

    @Override
    @TransactionalEventListener
    public boolean updateOrg(final ThirdPartyOrganizationEvent thirdPartyOrgEvent)
    {
        ...
    }

但是当我加载我的应用程序上下文时,我收到此错误

Caused by: java.lang.IllegalStateException: No TransactionalEventListener annotation found on method: public abstract boolean org.mainco.subco.myproject.service.ThirdPartyAPIService.updateOrg(org.mainco.subco.myproject.domain.ThirdPartyOrganizationEvent)
    at org.springframework.transaction.event.ApplicationListenerMethodTransactionalAdapter.<init>(ApplicationListenerMethodTransactionalAdapter.java:55)
    at org.springframework.transaction.event.TransactionalEventListenerFactory.createApplicationListener(TransactionalEventListenerFactory.java:55)
    at org.springframework.context.event.EventListenerMethodProcessor.processBean(EventListenerMethodProcessor.java:159)
    at org.springframework.context.event.EventListenerMethodProcessor.afterSingletonsInstantiated(EventListenerMethodProcessor.java:104)
    ... 34 more

我需要做什么才能正确配置?

1 个答案:

答案 0 :(得分:1)

在接口方法上定义@TransactionalEventListener,而不是在实现接口的方法上为我工作。