0

Need to initialise a listener only if it required to, based on a flag which is set at app startup from external source and not from application.properties.

class PropertyClass {
      boolean flag;
..
getters 
setters
..

}

@Configuration
class classSettingProperties () {

    @Bean 
    public  PropertyClass propertyClass() {
         PropertyClass propertyClass = new PropertClass () ;

         propertyClass.setflag(true or false);
         // Just an example how this property is set.

         return propertyClass; 

    }
}

@Component
public class ListenerClass {

    @JmsListener (... destination and factory details)
    public void listenerMethod () {
    .
    .
    .
    }

}
pvjhs
  • 549
  • 1
  • 9
  • 24

1 Answers1

0

Set the listener container factory autoStartup property to true(default) or false, according to your desired behavior.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Thanks for the solution i will try it. Till now i used JmsListenerEndpointRegistrar and registered the listener only if flag is on. What difference will it make in the 2 approches other then little extra code in the second approach. – pvjhs Feb 25 '19 at 14:45
  • There is not really much difference. – Gary Russell Feb 25 '19 at 14:59