Announcement Announcement Module
Collapse
No announcement yet.
Mongo Event Listener Problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mongo Event Listener Problem

    How do i register the mongo event listener ?

    I tried this :

    Code:
    public class MyListener extends AbstractMongoEventListener<BeforeSaveEvent<MyDomainModelThatIsSaved>> {
    	@Override
    	public void onBeforeSave(BeforeSaveEvent<MyDomainModelThatIsSaved> source, DBObject dbo) {
    		System.out.println("saving : " + dbo);
    		System.out.println("saving : " + dbo.toMap());
    		throw new RuntimeException("hehehe");
    	}
    }
    and register it to my springContext.xml :
    HTML Code:
    <bean id="myListener" class="my.package.MyListener" />
    And it doesnt work. The logging is not appearing, the exception is not thrown.

    I tried using extends AbstractMongoEventListener without any diamond generic type, an NPE occurs when the bean is being loaded <-- which proofs that the listener bean is loaded.

    What did i miss ?

    Thank you !

  • #2
    You have to type the AMEL to your domain type directly, not wrapped inside the event. So

    Code:
    public class MyListener extends AbstractMongoEventListener<MyDomainModelThatIsSaved> {
    
    }
    should do the trick. Regarding the NullPointException I created a ticket [0] and have fixed it [1] on our side. Downside is that we're stumbling over a bug in GenericTypeResolver [2] now producing another NullPointException. This will be fixed in 3.0.7 and already has been since 3.1.0.RC1. So you're actually only safe against the NPW with a recent 3.1 Spring version but we recommend typing the implementation class anyway.

    [0] https://jira.springsource.org/browse/DATAMONGO-333
    [1] https://github.com/SpringSource/spri...8cbb52ece0f283
    [2] https://jira.springsource.org/browse/SPR-8698

    Comment


    • #3
      It works fine now.

      Thank you !

      Comment

      Working...
      X