Commits

Stefan Saasen committed 6590ec2

Move the listener registration out of the ctor.

Don't let the this reference escape during construction.

  • Participants
  • Parent commits 26d4a6b

Comments (0)

Files changed (1)

File src/main/java/com/atlassian/labs/hipchat/components/AnnotatedListener.java

 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.DisposableBean;
+import org.springframework.beans.factory.InitializingBean;
 
 import java.util.StringTokenizer;
 
-public class AnnotatedListener implements DisposableBean {
+public class AnnotatedListener implements DisposableBean, InitializingBean {
     private static final Logger log = LoggerFactory.getLogger(AnnotatedListener.class);
 
     protected EventPublisher eventPublisher;
         this.eventPublisher = eventPublisher;
         this.applicationProperties = applicationProperties;
         this.configurationManager = configurationManager;
-        eventPublisher.register(this);
         this.hipChatProxyClient = new HipChatProxyClient(configurationManager, webResourceUrlProvider);
         this.userAccessor = userAccessor;
         this.personalInformationManager = personalInformationManager;
     public void destroy() throws Exception {
         eventPublisher.unregister(this);
     }
+
+    @Override public void afterPropertiesSet() throws Exception
+    {
+        eventPublisher.register(this);
+    }
 }