BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext

2

I'm having this error when running my application:

05-Oct-2016 21:18:25.586 SEVERE [localhost-startStop-26] org.apache.catalina.core.StandardContext.listenerStop Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener
 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:171)
    at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1090)
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1064)
    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1010)
    at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:558)
    at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:143)
    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4780)
    at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5417)
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:229)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:164)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:702)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:596)
    at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1805)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

Would anyone help me with it? As I do not handle it much I think it might be some wrong configuration or something like ...

Here are my configuration files:

-persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="contabgerencial" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>br.com.wmsi.modelo.V_Produto_Preferencia</class>
    <class>br.com.wmsi.modelo.V_Produtos_Cardapio</class>
    <class>br.com.wmsi.modelo.Tab_Operadoras</class>
    <class>br.com.wmsi.modelo.Tab_Item_Comanda</class>
    <class>br.com.wmsi.modelo.V_Itens_Consumidos_Comanda</class>
    <class>br.com.wmsi.modelo.Tab_Comanda</class>
    <class>br.com.wmsi.modelo.Tab_Mesas</class>
    <class>br.com.wmsi.modelo.Tab_Produto</class>
    <class>br.com.wmsi.modelo.Tab_Menu_Cardapio</class>
    <class>br.com.wmsi.modelo.Tab_Menu_Cardapio</class>
    <properties>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /> 
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/cmlight?zeroDateTimeBehavior=convertToNull" /> 
      <property name="javax.persistence.jdbc.user" value="root" /> 
      <property name="javax.persistence.jdbc.password" value="123" />
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
      <property name="hibernate.hbm2ddl.auto" value="update"/>
      <property name="hibernate.show_sql" value="true"/>
      <property name="hibernate.format_sql" value="true"/>
      <property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider"/>
      <property name="hibernate.c3p0.max_size" value="100"/>
      <property name="hibernate.c3p0.min_size" value="5"/>
      <property name="hibernate.c3p0.acquire_increment" value="1"/>
      <property name="hibernate.c3p0.idle_test_period" value="300"/>
      <property name="hibernate.c3p0.max_statements" value="100"/>
      <property name="hibernate.c3p0.timeout" value="100"/>
      <property name="hibernate.c3p0.unreturnedConnectionTimeout" value="400"/>
      <property name="hibernate.c3p0.debugUnreturnedConnectionStackTraces" value="true"/>
    </properties>
  </persistence-unit>
</persistence>
  • web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
    <display-name>SG_Restaurante</display-name>
    <welcome-file-list>
      <welcome-file>/WEB-INF/views/FormLogin.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>springmvc</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <init-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>
            /WEB-INF/spring-context.xml
          </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
      <servlet-name>springmvc</servlet-name>
      <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>WEB-INF/spring-context.xml</param-value>
    </context-param>
</web-app>
  • spring-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    <context:component-scan base-package="br.com.wmsi.controller" />
    <mvc:annotation-driven />
    <mvc:default-servlet-handler />
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/"/>
        <property name="suffix" value=".jsp"/>
    </bean>
</beans>

I only have these configuration files. If anyone can help me, thank you in advance.

    
asked by anonymous 06.10.2016 / 02:48

1 answer

-1

Have you tested your connection to the bank to see if the connection is OK? If not, before the last key of your connection class, put:

public static void main(String args[])
{
}

and try to run to see if your connection is active and give a Shift + F6 . I hope I have helped.

    
06.10.2016 / 02:58