2014-02-17 5 views
4

나는이 web.xml 파일을 통해 콩에 액세스하기 전에 '새로 고침'을 부르는 콩BeanFactory를 초기화 이미 닫혀 있지 - ApplicationContext를

<?xml version="1.0" encoding="UTF-8"?> 

<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:p="http://www.springframework.org/schema/p" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:jee="http://www.springframework.org/schema/jee" 
     xmlns:tx="http://www.springframework.org/schema/tx" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
          http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd 
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"> 

    <tx:annotation-driven transaction-manager="txManager"/> 


    <bean id="txManager" 
     class="org.springframework.jdbc.datasource.DataSourceTransactionManager" 
     p:dataSource-ref="dataSource"/> 


    <jee:jndi-lookup id="dataSource" jndi-name="pull_DS" resource-ref="true"/> 

    <bean id="sqlMapClient" 
     class="org.springframework.orm.ibatis.SqlMapClientFactoryBean" 
     p:configLocation="classpath:pull/DBUtils/sqlMapConfig.xml" 
     p:dataSource-ref="dataSource"/> 

    <bean id="daoBase" abstract="true" 
     p:sqlMapClient-ref="sqlMapClient"/> 

    <bean id="Photo" 
     class="pull.DBUtils.PopPhotoImpl" 
     parent="daoBase"/> 

    <bean id="Trunkcate" 
     class="pull.DBUtils.TrunkcateCifSrcImpl" 
     parent="daoBase"/> 

    <bean id="applicationContextProvder"class="pull.DBUtils.ApplicationContextProvider"/>  
</beans> 

과 ApplicationContextProvider을 포함

<context-param> 
<param-name>contextConfigLocation</param-name> 
<param-value>/WEB-INF/spring-context.xml /WEB-INF/core-spring-beans.xml 
</param-value> 
</context-param> 

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

와의 ApplicationContext .java for ApplicationContext

import org.springframework.beans.BeansException; 
import org.springframework.context.ApplicationContext; 
import org.springframework.context.ApplicationContextAware; 

public class ApplicationContextProvider implements ApplicationContextAware { 

    private static ApplicationContext ctx = null; 

    public static ApplicationContext getApplicationContext() { 
     return ctx; 
    } 

    public void setApplicationContext(ApplicationContext ctx) 
      throws BeansException { 
     this.ctx = ctx; 
    } 
} 

그래서 저는 ret 메소드를 정의했습니다.

import org.springframework.beans.BeansException; 
import org.springframework.beans.factory.NoSuchBeanDefinitionException; 
import org.springframework.context.ApplicationContext; 


public class TrunkcateCifSrcImpl extends iBatisTemplate implements TrunkcateCifSrc{ 


public int retTrunkcateReady() { 
    return super.trunkcateReady("CifSrc_Trunkcate.cleanUp"); 
} 

public static int returnCleanUp() { 
    TrunkcateCifSrcImpl trunkcate = null; 
    int result; 
    try { 
     ApplicationContext ctx = ApplicationContextProvider 
       .getApplicationContext(); 
     trunkcate = (TrunkcateCifSrcImpl) ctx.getBean("Trunkcate"); 
     result = trunkcate.retTrunkcateReady(); 
    } 
    catch (NoSuchBeanDefinitionException noBeanE) { 
     throw noBeanE; 
    } catch (BeansException beanE) { 
     throw beanE; 
    } 
    catch (Exception e) { 
     throw e; 
    } 
    return result; 
} 

} 

iBatisTemplate 클래스와 TrunkcateCifSrcImpl 콩의 urnCleanUp는

import java.sql.SQLException; 
import java.util.HashMap; 
import java.util.Iterator; 
import java.util.List; 
import java.util.Map; 

import org.springframework.dao.DataAccessException; 
import org.springframework.orm.ibatis.SqlMapClientCallback; 
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; 

import com.ibatis.sqlmap.client.SqlMapExecutor; 

public class iBatisTemplate extends SqlMapClientDaoSupport { 

    public int trunkcateReady(final String id) { 
     Map<String, Integer> map = new HashMap<String, Integer>(1); 
     getSqlMapClientTemplate().queryForObject(id, map); 
     return map.get("trunkcateReady"); 
    } 

    } 

(값은 데이터베이스에서 호출 iBatis를 함수에서 다시 반환)하지만 지금은 한 번 한동안 내가 호출하면지도 "trunkcateReady"의 값을 반환 Trunkcate 빈에서이 메서드를 예외 예외 IllegalStateException받을 것이다, 아무도 내가 이것을 해결하기 위해 할 수있는 것을 알고 있습니까 ?? 내가 가진

do{ 
    cleanUp = TrunkcateCifSrcImpl.returnCleanUp(); 
    if(cleanUp==1) 
    {  
     logger.debug("Going to sleep........"); 
     Thread.sleep(65000); 
    } 
}while(cleanUp!=0); 

스택 추적 예외, 이것은 일반적으로 다음에 Thread.sleep (65000) 한 후, 정상적으로

2014-02-14 12:23:45,646 GMT-0800 [managedServer=weeManagedServer-1]pull.quartzScheduler.PullingPDRTask - Pull failed.... 
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.getBean(AbstractApplicationContext.java:1093) 
    at pull.DBUtils.TrunkcateCifSrcImpl.returnCleanUp(TrunkcateCifSrcImpl.java:21) 
    at pull.quartzScheduler.PullingPDRTask.excute(PullingPDRTask.java:257) 
    at pull.quartzScheduler.SchedulerService.executePullingPDRTask(SchedulerService.java:31) 
    at pull.quartzScheduler.PullStatefulJob.executeInternal(PullStatefulJob.java:42) 
    at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:113) 
    at org.quartz.core.JobRunShell.run(JobRunShell.java:216) 
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549) 

덕분에 다시 갈 것이다는 루프를 통해 이동 처음 발생! 모든 입력이 도움이 될 것입니다. weblogic 서버 1036jdk1.7에 내 응용 프로그램을 배포합니다. 스프링 사용 3.1.1. 모두에게 감사드립니다!

+0

는 예외 스택 트레이스를 게시 할 수 있습니까? – Hrishikesh

+0

또한 truncateDAO. TruncateCifSrcImpl 클래스의 종속성으로 언급되어 있습니까? 그것은 XML 설정에서 그 방법을 보여주지 않습니다. – Hrishikesh

+0

실패한 스택 추적을 포함합니다. 그것은 getBean "Trunkcate"를 시도 할 때 실패했습니다. 이 전체 응용 프로그램은 Quartz를 사용하여 30 분마다 스케줄링하고 깨우며 "returnCleanUp"은 "executePullingPDRTask"의 일부입니다. cleanUp이 여전히 반환되면! = 0, "returnCleanUp"이 계속 호출됩니다. 추신 : 그것이 도움이 될지 모르겠지만, 나는 여러 스레드를 줄이기 위해 쿼츠 스레드 = 1을 설정했습니다. 감사! – eclipznightz

답변

1

Tomcat 6을 사용하여 Spring MVC에서 작업했을 때 비슷한 문제가 있었지만 같은 이름의 여러 빈 클래스를 실수로 선언했다면 클래스를 한 번 모호하게 검사했습니다. 전체 스택 추적을 게시하십시오.

만약 내가 도움이된다면 이것은 실수 였고 나는 실수를 범했다. bean 클래스 [com.ssrv.fms.service.contact.impl.CountryServiceImpl]에 대한 어노테이션으로 지정된 bean 이름 'countryServiceImpl'이 기존의 호환되지 않는 bean 정의와 동일한 이름 및 클래스 [com.ssrv.fms.service]와 충돌합니다. admin.impl.CountryServiceImpl]

0

프로젝트의 대상 폴더를 확인하고 구성 파일이 있는지 확인할 수 있습니다.

errorInfo에 대한 자세한 내용을 알려 주시면 도움이 될 것 같습니다.

나는 당신과 같은 문제를 만났습니다. 하지만이

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

에서 더 자세한 오류 정보를 가지고 그것은

Caused by: java.io.FileNotFoundException: class path resource [spring/] cannot be resolved to URL because it does not exist 

그래서 내가 프로젝트의 대상 폴더를 확인하십시오 "봄"폴더가 누락라고하는 내 모든 설정 파일에서 그것. 비록 내가 왜 거기에 있지는 모르겠지만.

그래서 프로젝트의 대상 폴더를 삭제하고 다시 빌드합니다. 그리고 문제가 해결되었습니다. 'spring'폴더가 나타납니다.

전후 :

before after

관련 문제