Announcement Announcement Module
Collapse
No announcement yet.
Spring JNDI: How do you specify multiple resources to lookup? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring JNDI: How do you specify multiple resources to lookup?

    I tried the following in the application context:
    Code:
        <jee:jndi-lookup id="log4jJndi" jndi-name="log4j" resource-ref="true" />
        <jee:jndi-lookup id="configurationsJndi" jndi-name="configurations" resource-ref="true" />
    but I keep getting this error when specifying more than one jndi lookup. In Glassfish, I have two JNDI resources that the application needs, one is for configurations specific towards the application and the other is for logging using log4j.

    Code:
    Exception while loading the app : java.lang.IllegalStateException:  
    ContainerBase.addChild: start: org.apache.catalina.LifecycleException:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'log4jJndi': Invocation of init method failed; 
    nested exception is javax.naming.CommunicationException: Communication exception for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is java.lang.IllegalAccessException: value cannot be null]|#]
    Since removing one of the JNDI look ups it works deploying the application to a container. My question is then, how do you specify more than one JNDI look up or how do you have one JNDI look up look up more than one JNDI resource?

    Edit: Solved it in the application context I used propertiesArray and then added the log4j value to a config bean.

    Code:
    <jee:jndi-lookup id="log4jJndi" jndi-name="log4j" resource-ref="true" />
        <jee:jndi-lookup id="configurationsJndi" jndi-name="configurations" resource-ref="true" />
        
        <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="ignoreUnresolvablePlaceholders" value="true"/>        
            <property name="propertiesArray">
                <list>
                    <ref bean="configurationsJndi"/>
                    <ref bean="log4jJndi"/>
                </list>
            </property>
        </bean>
    
        <bean id="config" class="com.foo.Config">
            <constructor-arg>
                <bean class="org.springframework.util.StringUtils" factory-method="commaDelimitedListToSet">
                    <constructor-arg type="java.lang.String" value="${com.foo.file.location}"/>
                </bean>
            </constructor-arg>
            <property name="log4jFileLocation" value="${com.foo.logPath}" />
        </bean>
    Last edited by ColinMc; Jan 2nd, 2013, 03:32 PM.
Working...
X