There is Java class which should have int MY_LISTENER_PORT
with injected my.listener.port value from a properties file:
@Singleton
public class MyListener {
@Inject
@Named("my.listener.port")
private int MY_LISTENER_PORT;
public MyListener(){
start();
}
public void start() {
System.out.println("Port: " + MY_LISTENER_PORT);
}
}
Which is bind as eager singleton with Guice in:
public class BootstrapServletModule extends ServletModule {
@Override
protected void configureServlets() {
...
bind(MyListener.class).asEagerSingleton();
...
}
}
Sometimes when Tomcat starts up, I get properly injected value to MY_LISTENER_PORT, for example: "Port: 9999". Sometimes, it is not injected and I get "Port: 0". Why does it happen?