Bean工厂未初始化或已关闭 - 通过ApplicationContext的

我有这个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。谢谢大家!

回答:

我有一个类似的问题,当我在使用Tomcat 6的Spring MVC上工作时,但我错误地声明了多个具有相同名称的bean类,请检查您的类是否有歧义。请发布完整的堆栈跟踪。

只是万一它有助于这是我的错误,所以我得到了那个错误。 用于bean类[com.ssrv.fms.service.contact.impl.CountryServiceImpl]的注释指定的bean名称'countryServiceImpl'与具有相同名称和类的现有非兼容bean定义[com.ssrv.fms.service。 admin.impl.CountryServiceImpl]

回答:

您可以检查项目的目标文件夹,并检查配置文件是否存在。

而且我认为你应该告诉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'文件夹。

前后:

以上是 Bean工厂未初始化或已关闭 - 通过ApplicationContext的 的全部内容, 来源链接: utcz.com/qa/258787.html

回到顶部