0

J'utilise Spring 4.3.8.RELEASE avec Hibernate 5.1.5.Final. Je veux qu'une méthode soit exécutée après qu'une autre transaction soit terminée. Cette transaction est définie ci-dessousWny je reçois "java.lang.IllegalStateException: No Annotation TransactionalEventListener"?

@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 

est la méthode Voici donc que je veux exécuter après l'opération ci-dessus complète ...

@Service 
public class ThirdPartyAPIServiceImpl implements ThirdPartyAPIService 
{ 

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

Mais quand je charge mon contexte d'application je reçois cette erreur

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 

Que dois-je faire pour que cela soit configuré correctement?

Répondre

0

Définition @TransactionalEventListener sur la méthode d'interface plutôt que sur la méthode implémentant l'interface travaillée pour moi.