2014-02-17 43 views
4

我有這個web.xml文件訪問豆之前所說的「刷新」Bean工廠未初始化或已關閉 - 通過ApplicationContext的

<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包括Bean的

<?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 .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 urnCleanUp在TrunkcateCifSrcImpl bean作爲

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類返回地圖「trunkcateReady」的價值

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的函數返回),但現在曾經在一段時間,如果我打電話這個方法來自Trunkcate bean我會收到異常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」將保持呼叫。 Ps:不確定是否有幫助,我將ony set石英線= 1以減少多重線程。謝謝! – eclipznightz

回答

1

我有一個類似的問題,當我在使用Tomcat 6的Spring MVC上工作時,但我錯誤地聲明瞭多個具有相同名稱的bean類,請檢查您的類是否有歧義。請發佈完整的堆棧跟蹤。

只是萬一它有助於這是我的錯誤,所以我得到了那個錯誤。 用於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

相關問題