1

Sorry for my English. I use Eclipse 3.7, that runs web-app (spring-mvc + spring-secirity) on tomcat6, but happens next error:

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:1071)
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1045)
    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:993)
    at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:548)
    at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:142)
    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4245)
    at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4886)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4750)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

Can anyone help me please?

4

2 回答 2

4

I have seen this stacktrace before when working on a project that uses Spring 3.0.6 and runs in JBoss.

When I have seen this, it was inevitably in conjunction with database connectivity or permission issues.

Here is another developer who encountered this issue and it was also related to communication with the database: How can I cope with “IllegalStateException: BeanFactory not initialized or already closed”?

There is another developer on this thread who commented that he had a similar exception, and his was caused by a bad Spring Security configuration file.

Also, you may want to check into where you have placed the Spring JARs. Here is a relevant post: Spring Tomcat issue.

Finally, there are certain versions of application servers where this error could be caused by a bug in the application server. Here is a post on SpringSource forums regarding a bug in Weblogic 9.2 MP2. Here is another post regarding a bug in a particular version of jbossws.

Good luck, hope this helps.

于 2012-08-30T19:03:20.917 回答
0

The above mentioned solution is the exact accurate solution. But sometimes there are same issues related BeanFactory not initialized or already closed ...still persist after applying solution. In that case you should try to clean your tomcat directory. Delete your target folder and rebuild your artefact.

This solution is for most rare BeanFactory issues but less in frequency which can be resolved by following the way I mentioned.

于 2019-01-02T13:59:37.623 回答