SHARE
TWEET

Untitled

a guest Oct 16th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package io.pivotal.microservices.cms.custom;
  2.  
  3. import org.hibernate.search.jpa.FullTextEntityManager;
  4. import org.hibernate.search.jpa.Search;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.boot.context.event.ApplicationReadyEvent;
  7. import org.springframework.context.ApplicationListener;
  8. import org.springframework.stereotype.Component;
  9.  
  10. import javax.persistence.EntityManager;
  11.  
  12. @Component
  13. public class StartupListener implements ApplicationListener<ApplicationReadyEvent> {
  14.  
  15.     private EntityManager entityManager;
  16.  
  17.     /*@Autowired
  18.     public StartupListener(final EntityManagerFactory entityManagerFactory) {
  19.         entityManager = entityManagerFactory.createEntityManager();
  20.     }*/
  21.  
  22.     @Autowired
  23.     public StartupListener(EntityManager entityManager) {
  24.         this.entityManager = entityManager;
  25.     }
  26.  
  27.     @Override
  28.     public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
  29.         FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
  30.         try {
  31.             fullTextEntityManager.createIndexer().startAndWait();
  32.         } catch(InterruptedException e) {
  33.             e.printStackTrace();
  34.         }
  35.     }
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top