1 Reply Latest reply on May 31, 2012 4:39 AM by jomu78

    Forcing singleton reload

    jomu78 Newbie



      when the configuration in my application changes, I need to reload some stuff. So I have an EventListener


      public interface ConfigurationListener extends EventListener {
        public void reloadConfiguraiton();


      A singleton makes use of the configuration bean which can fire the ConfigurationEvent but when I add "implements ConfigurationListener" and the blank implementation of the above message I get an error message like


       org.jboss.as.server.deployment.DeploymentUnitProcessingException: No component found for type 'test.SingletonTestBean' with name null

      Without implementing the interface it is running as requested (except the config reload does not work for sure). This is running on Jboss 7.0.2 - why do I get the above error message


      Is there a better possibility to force Jboss itself to recreate the Singleton on request?




        • 1. Re: Forcing singleton reload
          jomu78 Newbie



          I found a solution using CDI (JSR 299 / 330). Instead of using the listeners I now inject an javax.enterprise.event.Event instead.


          Event<ConfigurationReloadEvent> event;


          ConfigReloadEvent is an empty class as I do not need any payload at the moment. When the configurtion is reloaded, I simply need to "fire" this event.

          event.fire(new ConfigurationReloadEvent());


          The listeners are also configured using annotations

          public void reloadConfiguraiton(@Observes ConfigurationReloadEvent event) {
            // do what ever needs to be done when notfied about config reload


          So no need to destroy and re-create the singletons, they just listen on the event and do whats needed. You only have to take care about the synchronisation - you never know when the event is fired and in which status your application currently is.