Announcement Announcement Module
Collapse
No announcement yet.
Injecting a Spring dependency into a JPA EntityListener Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Injecting a Spring dependency into a JPA EntityListener

    Hello,

    I am trying to inject a Spring dependency into an JPA EntityListener.

    Here is my listener class:

    Code:
    @Configurable(autowire = Autowire.BY_TYPE, dependencyCheck = true)
    public class PliListener {
    
        @Autowired
        private EvenementPliRepository evenementPliRepository;
    
        @PostPersist
        void onPostPersist(Pli pli) {
            EvenementPli ev = new EvenementPli();
            ev.setPli(pli);
            ev.setDateCreation(new Date());
            ev.setType(TypeEvenement.creation);
            ev.setMessage("Création d'un pli");
            System.out.println("evenementPliRepository: " + evenementPliRepository);
            evenementPliRepository.save(ev);
        }
    
    
    }
    Here is my Entity class:

    Code:
    @RooJavaBean
    @RooToString
    @RooJpaActiveRecord
    @EntityListeners(PliListener.class)
    public class Pli implements Serializable{
    ...
    However, my dependency (i.e. evenementPliRepository) is always null.

    Can anyone please help?

    Regards,

    Julien.
Working...
X