Saturday, March 14, 2015

BeanFactory not initialized or already closed Error Fix For ActiveMQ In Windows

Are you getting same kind of exceptions as below while starting Apache ActiveMQ in Windows?
Caused by: java.io.IOException: Failed to bind to server socket: tcp://0.0.0.0:61616?maximumConnections=1000&wireformat.maxFrameSize=104857600 due to: java.net.BindException: Address already in use: JVM_Bind
        at org.apache.activemq.util.IOExceptionSupport.create(IOExceptionSupport.java:33)
        at org.apache.activemq.transport.tcp.TcpTransportServer.bind(TcpTransportServer.java:135)
        at org.apache.activemq.transport.tcp.TcpTransportFactory.doBind(TcpTransportFactory.java:56)
        at org.apache.activemq.transport.TransportFactorySupport.bind(TransportFactorySupport.java:40)
        at org.apache.activemq.broker.TransportConnector.createTransportServer(TransportConnector.java:307)
        at org.apache.activemq.broker.TransportConnector.getServer(TransportConnector.java:139)
        at org.apache.activemq.broker.TransportConnector.asManagedConnector(TransportConnector.java:106)
        at org.apache.activemq.broker.BrokerService.registerConnectorMBean(BrokerService.java:1965)

Caused by: java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
        at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:172)
        at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1078)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
        at org.apache.xbean.spring.context.ResourceXmlApplicationContext.<init>(ResourceXmlApplicationContext.java:64)
        at org.apache.xbean.spring.context.ResourceXmlApplicationContext.<init>(ResourceXmlApplicationContext.java:52)
        at org.apache.activemq.xbean.XBeanBrokerFactory$1.<init>(XBeanBrokerFactory.java:101)
        at org.apache.activemq.xbean.XBeanBrokerFactory.createApplicationContext(XBeanBrokerFactory.java:101)
        at org.apache.activemq.xbean.XBeanBrokerFactory.createBroker(XBeanBrokerFactory.java:65)
        at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:71)
        at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:54)
        at org.apache.activemq.console.command.StartCommand.startBroker(StartCommand.java:125)
        at org.apache.activemq.console.command.StartCommand.runTask(StartCommand.java:84)

That has most probably happened due to Internet Connection Sharing (ICS) service if you are using Windows 7. This service happens to run on same port as ActiveMQ. So if it starts before ActiveMQ launch, ActiveMQ will throw exception during start up. I used to get this error intermittently in my Windows Laptop because in one network adapter ICS was enabled. I disabled it as I didn't require it. From then on, I never had any issues.

1 comment: