Announcement Announcement Module
No announcement yet.
spring-data-mongo repo cant be initialised if referenced via a beanPostProcessor Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring-data-mongo repo cant be initialised if referenced via a beanPostProcessor

    Hi All,
    briefly, I'm trying to use spring-data-mongo in a web context along with apache shiro.
    using spring 3.2.0-release

    shiro uses an instance of a beanPostProcessor to init itself. This in turn eventually references a spring-data-mongo based userDao in my custom shiro realm.

    The autoProxy versions of the repository (extends mongoRepository etc) dont work at all when initialised like this,
    so I tried extending SimpleMongoRepository in my DAO.
    this works when its allowed to start normally, but not via a beanPostProcessor.

    the exception is java.lang.IllegalStateException: ApplicationEventMulticaster not initialized

    the root cause seems to be that in order to instantiate a SimpleMongoRepository I need to call MongoRepositoryFactory(template).<User, String>getEntityInformation(User.class)
    this method eventually lands in appingContext,
    where it creates a new PersistentEntity and then tries to publish an ApplicationEvent.

    unfortunately beanPostProcessors seem to be run before ApplicationEventMulticaster is still ever initialized so cannot work if they try to raise ApplicationEvents during startup.

    Is this a problem with my setup? or is it a fault of spring-data-mongo for attempting to raise an event here?
    or a fault in spring for not making the ApplicationEventMulticaster available for entities initialised from a beanPostProcessor?

    how best to proceed?


  • #2
    Hi there,
    I've encountered exactly the same issue. Did you manage to find a solution or a workaround?
    Thanks in advance


    • #3
      As a workaround you can inject a mongooperations/template instead. Not perfect but it works.