无法在容器外使用弹簧豆。总是拿起WebSphere Context

时间:2010-04-15 19:21:28

标签: java spring websphere

我们在我们的项目中定义了很多spring bean,我们在Websphere中部署了^。一个例子如下:

<bean id="oasJdbcData" class="oracle.jdbc.pool.OracleConnectionCacheImpl">
        <property name="driverType">
            <value>oracle.jdbc.driver.OracleDriver</value>
        </property>
        <property name="URL">
            <value>jdbc:oracle:thin:@oracle:1521:OASIS</value>
        </property>
        <property name="user">
            <value>oasis_owner</value>
        </property>
        <property name="password">
            <value>o3ngin33r</value>
        </property>
    </bean>

现在我们有一个服务定位器类,如下面的

private static ServiceLocator serviceLocator = new ServiceLocator();

private static ApplicationContext beanFactory = new ClassPathXmlApplicationContext(APPLICATION_CONTEXT_LOCATION);

protected ServiceLocator() { 
}

public ApplicationContext getBeanFactory() {
    return beanFactory;
}

public static ServiceLocator getInstance() {
    return serviceLocator;

现在,当我尝试从我的jUnit

执行此操作时
ServiceLocator.getInstance().getBean("oasJdbcData";

获得以下异常

Caused by: javax.naming.ServiceUnavailableException: Could not obtain an initial context due to a communication failure. Since no provider URL was specified, the default provider URL of "corbaloc:iiop:1.0@192.168.255.1:2809/NameService" was used.  Make sure that any bootstrap address information in the URL is correct and that the target name server is running.  Possible causes other than an incorrect bootstrap address or unavailable name server include the network environment and workstation network configuration. [Root exception is org.omg.CORBA.TRANSIENT: java.net.ConnectException: Connection refused: connect:host=192.168.255.1,port=2809  vmcid: IBM  minor code: E02  completed: No]
    at com.ibm.ws.naming.util.WsnInitCtxFactory.mapInitialReferenceFailure(WsnInitCtxFactory.java:1968)
    at com.ibm.ws.naming.util.WsnInitCtxFactory.mergeWsnNSProperties(WsnInitCtxFactory.java:1172)
    at com.ibm.ws.naming.util.WsnInitCtxFactory.getRootContextFromServer(WsnInitCtxFactory.java:720)
    at com.ibm.ws.naming.util.WsnInitCtxFactory.getRootJndiContext(WsnInitCtxFactory.java:643)
    at com.ibm.ws.naming.util.WsnInitCtxFactory.getInitialContextInternal(WsnInitCtxFactory.java:489)
    at com.ibm.ws.naming.util.WsnInitCtx.getContext(WsnInitCtx.java:113)
    at com.ibm.ws.naming.util.WsnInitCtx.getContextIfNull(WsnInitCtx.java:428)
    at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:144)
    at javax.naming.InitialContext.lookup(InitialContext.java:361)
    at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155)
    at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:88)
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:153)
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
    at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:104)
    at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
    at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:200)
    at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:186)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1368)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1334)
    ... 33 more

清楚地表明它正在寻找Websphere的IntialContext 我不想要的 任何人都可以告诉我我做错了什么?

1 个答案:

答案 0 :(得分:0)

您的平台(操作系统,尤其是网络设置)已搞砸。可能是您配置错误的路由设置,防火墙或DNS设置。有趣的是,修复那些可能无法修复您的WAS,因为它在创建配置文件时保存了某些设置。请在安装之前重新开始并确保平台健康。