处理缺少JNDI

时间:2016-09-07 13:54:21

标签: java spring jndi

我在spring中配置了JNDI引用

<bean id="optionalBean" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="name"/>
</bean>

但是可能没有配置此JNDI属性。在这种情况下,我的Tomcat无法启动 我怎么能告诉Spring这个JNDI是可选的?

更新: 添加lookupOnStartup后,我收到错误:

nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'optionalBean': Cannot resolve reference to bean 'optionalBean' while setting bean property 'optionalBean'; 
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'optionalBean': 
Invocation of init method failed; nested exception is java.lang.IllegalStateException: 
Cannot deactivate 'lookupOnStartup' without specifying a 'proxyInterface' or 'expectedType'

1 个答案:

答案 0 :(得分:0)

这应该

 <bean id="optionalBean" class="org.springframework.jndi.JndiObjectFactoryBean" lazy-init="true">
            <property name="jndiName" value="name"/>
        </bean>