복붙노트

[SPRING] BeanFactory가 초기화되지 않았거나 이미 닫혔습니다 - 전에 '새로 고침'을 호출하십시오.

SPRING

BeanFactory가 초기화되지 않았거나 이미 닫혔습니다 - 전에 '새로 고침'을 호출하십시오.

여기에 내 오류가 있습니다 :

나는이 오류를 얻고있다.

> SEVERE: Exception sending context initialized event to listener
> instance of class
> org.springframework.web.context.ContextLoaderListener
> java.lang.NoSuchMethodError:
> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.setEnvironment(Lorg/springframework/core/env/Environment;)V
>   at
> org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:87)
>   at
> org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
>   at
> org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:522)
>   at
> org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436)
>   at
> org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
>   at
> org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
>   at
> org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
>   at
> org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)
>   at
> org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
>   at
> org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
>   at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)    at
> java.util.concurrent.FutureTask.run(Unknown Source)   at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
>   at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
>   at java.lang.Thread.run(Unknown Source) Nov 21, 2013 12:54:38 PM
> org.apache.catalina.core.StandardContext startInternal SEVERE: Error
> listenerStart Nov 21, 2013 12:54:38 PM
> org.apache.catalina.core.StandardContext startInternal SEVERE: Context
> [/FLPalette] startup failed due to previous errors Nov 21, 2013
> 12:54:38 PM org.apache.catalina.core.ApplicationContext log INFO:
> Closing Spring root WebApplicationContext Nov 21, 2013 12:54:38 PM
> org.apache.catalina.core.StandardContext listenerStop SEVERE:
> 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:172)
>   at
> org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1066)
>   at
> org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1040)
>   at
> org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:988)
>   at
> org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:556)
>   at
> org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:142)
>   at
> org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4763)
>   at
> org.apache.catalina.core.StandardContext$4.run(StandardContext.java:5472)
>   at java.lang.Thread.run(Unknown Source)     at
> org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5481)
>   at
> org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:225)
>   at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)
>   at
> org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1033)
>   at
> org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:774)
>   at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
>   at
> org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1033)
>   at
> org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:291)
>   at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
>   at
> org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
>   at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
>   at
> org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:727)
>   at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
>   at org.apache.catalina.startup.Catalina.start(Catalina.java:620)    at
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)   at
> sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)   at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)   at
> java.lang.reflect.Method.invoke(Unknown Source)   at
> org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:303)   at
> org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:431) Nov 21,
> 2013 12:54:38 PM org.apache.coyote.AbstractProtocol start INFO:
> Starting ProtocolHandler ["http-bio-8080"] Nov 21, 2013 12:54:38 PM
> org.apache.coyote.AbstractProtocol start INFO: Starting
> ProtocolHandler ["ajp-bio-8009"] Nov 21, 2013 12:54:38 PM
> org.apache.catalina.startup.Catalina start

Pom.hml :

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.paypal.palette</groupId>
  <artifactId>FLPalette</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
   <name>FLPalette</name>
  <url>http://maven.apache.org</url>
  <dependencies>
  <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.5</version>
</dependency>
       <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${org.springframework.version}</version>
            </dependency>
            <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
        <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>  

  <dependency>
    <groupId>wsdl4j</groupId>
    <artifactId>wsdl4j</artifactId>
    <version>1.6.3</version>
    <scope>test</scope>
</dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>3.1.1.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>3.1.1.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.14</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>3.1.1.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.1.2</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <version>1.1.2</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>3.1.1.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>3.1.1.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>3.1.1.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>3.1.1.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>3.1.1.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>3.1.1.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-ldap</artifactId>
        <version>3.1.1.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.jcraft</groupId>
        <artifactId>jsch</artifactId>
        <version>0.1.50</version>
    </dependency>
    <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    </dependency>
    <dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-taglibs</artifactId>
    <version>3.1.0.RELEASE</version>
    </dependency>
    <dependency>
    <groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>20090211</version>
    </dependency>   
    <dependency>
   <groupId>commons-fileupload</groupId>
   <artifactId>commons-fileupload</artifactId>
   <version>1.2.1</version> 
    </dependency>   
     <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>1.4</version>
    </dependency>           
  </dependencies>
  <properties>
        <org.springframework.version>3.0.2.RELEASE</org.springframework.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
  <build>
    <finalName>${project.artifactId}</finalName>   
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
      <plugin>
           <artifactId>maven-war-plugin</artifactId>           
       </plugin>
    </plugins>
  </build>  
</project>

해결법

  1. ==============================

    1.이 예외는 Listener ContextLoaderListener를 제공하기 때문에 발생합니다.

    이 예외는 Listener ContextLoaderListener를 제공하기 때문에 발생합니다.

    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    

    컨텍스트 매개 변수를 제공하지 않습니다. 봄 구성 파일 용. applicationContext.xml과 같은 구성에 대한 스 니펫 아래에 제공해야합니다.

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>applicationContext.xml</param-value>
    </context-param>
    

    Java 기반 스프링 구성을 제공하는 경우 해당 시점에 봄 구성에 XML 파일을 사용하지 않는다는 것을 의미하므로 아래 코드를 제공해야합니다.

    <!-- Configure ContextLoaderListener to use AnnotationConfigWebApplicationContext
    instead of the default XmlWebApplicationContext -->
    <context-param>
        <param-name>contextClass</param-name>
        <param-value>
        org.springframework.web.context.support.AnnotationConfigWebApplicationContext
        </param-value>
    </context-param>
    
    <!-- Configuration locations must consist of one or more comma- or space-delimited
    fully-qualified @Configuration classes. Fully-qualified packages may also
    be specified for component-scanning -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>com.nirav.modi.config.SpringAppConfig</param-value>
    </context-param>
    
  2. ==============================

    2.여기서 문제는 사용중인 스프링 웹 버전 (3.1.1-RELEASE)이 사용중인 스프링 콩 버전 (3.0.2-RELEASE)과 호환되지 않는다는 것입니다. 스택 맨 위에서 NoSuchMethodError를 볼 수 있습니다. 그러면 NoPuchMethodError가 초기화되지 않은 BeanFactory를 예외로 트리거합니다.

    여기서 문제는 사용중인 스프링 웹 버전 (3.1.1-RELEASE)이 사용중인 스프링 콩 버전 (3.0.2-RELEASE)과 호환되지 않는다는 것입니다. 스택 맨 위에서 NoSuchMethodError를 볼 수 있습니다. 그러면 NoPuchMethodError가 초기화되지 않은 BeanFactory를 예외로 트리거합니다.

    NoSuchMethodError는 spring-web의 메소드 호출 XmlWebApplicationContext.loadBeanDefinitions ()가 3.0.2-RELEASE에없는 스프링 - 콩에서 XmlBeanDefinitionReader.setEnvironment ()를 호출하려고하기 때문에 발생합니다. 그러나 setEnvironment는 부모 AbstractBeanDefinitionReader에서 상속되므로 3.1.1-RELEASE에 존재합니다.

    이 문제를 해결하려면 spring-beans jar 파일을 3.1.1-RELEASE로 업그레이드하는 것이 가장 좋습니다. 이 jar의 버전은 pom.xml에 매개 변수로 표시되며 파일의 org.springframework.version 속성에 의해 제어됩니다.

  3. ==============================

    3.문제가되는 프로젝트를 서버의 배포 (JBoss Dev Studio에서 서버를 마우스 오른쪽 단추로 클릭하고 서버보기에서 프로젝트를 "제거")에서 제거하고 다음을 수행 할 때까지이 문제가 발생했습니다.

    문제가되는 프로젝트를 서버의 배포 (JBoss Dev Studio에서 서버를 마우스 오른쪽 단추로 클릭하고 서버보기에서 프로젝트를 "제거")에서 제거하고 다음을 수행 할 때까지이 문제가 발생했습니다.

    그런 다음 프로젝트 자체가 아닌 서버를 선택하여 서버를 디버그 또는 실행 모드로 다시 시작하십시오.

    이것은 모든 이전 설정 / 상태 / 메모리 / 문제를 일으키는 것이 무엇이든지 플러시하는 것처럼 보였습니다. 그리고 더 이상 오류가 없습니다.

  4. ==============================

    4.필자의 경우, "BeanFactory가 초기화되지 않았거나 이미 닫혔습니다."라는 오류는 서버 시작시 알아 채지 못했던 이전 오류의 결과였습니다. 나는 그것이 항상 문제의 진정한 원인은 아니라고 생각합니다.

    필자의 경우, "BeanFactory가 초기화되지 않았거나 이미 닫혔습니다."라는 오류는 서버 시작시 알아 채지 못했던 이전 오류의 결과였습니다. 나는 그것이 항상 문제의 진정한 원인은 아니라고 생각합니다.

  5. ==============================

    5.이 문제는 3.2.1에서 3.2.18로, 3.2.8에서 4.3.5로 업그레이드 할 때 한 번 두 번 나타났습니다. 두 경우 모두이 오류는 스프링 모듈의 버전이 다르기 때문에 발생합니다

    이 문제는 3.2.1에서 3.2.18로, 3.2.8에서 4.3.5로 업그레이드 할 때 한 번 두 번 나타났습니다. 두 경우 모두이 오류는 스프링 모듈의 버전이 다르기 때문에 발생합니다

  6. ==============================

    6.필자의 경우이 오류는 로그에서 발견 된 네트워크 연결 오류로 인한 것입니다.

    필자의 경우이 오류는 로그에서 발견 된 네트워크 연결 오류로 인한 것입니다.

  7. ==============================

    7.springframework 초기화 리포지토리 또는 컨트롤러 주석 내부의 스프링 프레임 워크에서 동일한 클래스 이름은 기본 인스턴스 만 존재할 수 있으므로 값 이름을 설정할 수 있습니다

    springframework 초기화 리포지토리 또는 컨트롤러 주석 내부의 스프링 프레임 워크에서 동일한 클래스 이름은 기본 인스턴스 만 존재할 수 있으므로 값 이름을 설정할 수 있습니다

  8. ==============================

    8.내 경우에는 오류가 유효했고 try with resource를 사용했기 때문에 발생했습니다.

    내 경우에는 오류가 유효했고 try with resource를 사용했기 때문에 발생했습니다.

     try (ConfigurableApplicationContext cxt = new ClassPathXmlApplicationContext(
                        "classpath:application-main-config.xml")) {..
    }
    

    그것은 자동으로 다른 콩 에서이 컨텍스트를 재사용하고 싶지 않아야 스트림을 닫습니다.

  9. ==============================

    9.동일한 오류가 있었고 응용 프로그램 구성 또는 web.xml을 변경하지 않았습니다. 코드에 대한 사소한 변경 사항을 되돌리려 고 여러 번 시도해도 예외가 지워지지 않았습니다. 마지막으로 STS를 다시 시작한 후에 작동합니다.

    동일한 오류가 있었고 응용 프로그램 구성 또는 web.xml을 변경하지 않았습니다. 코드에 대한 사소한 변경 사항을 되돌리려 고 여러 번 시도해도 예외가 지워지지 않았습니다. 마지막으로 STS를 다시 시작한 후에 작동합니다.

  10. from https://stackoverflow.com/questions/20114955/beanfactory-not-initialized-or-already-closed-call-refresh-before by cc-by-sa and MIT license