Spring对JNDI的支持的配置实例

1. 使用JndiObjectFactoryBean,例如
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName">
        <value>java:/MySqlDS</value>
    </property>
</bean>

2. 使用JndiObjectTargetSource,例如
<bean id="queueTarget" class="org.springframework.jndi.JndiObjectTargetSource">
    <property name="jndiName">
        <value>queue/testQueue</value>
    </property>
</bean>

3. 如果不使用JndiTemplate实现InitialContext环境变量的配置,则需要jndi.properties文件(放在classpath中,一般放在src下面),内容如下
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jnp://localhost:1099
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

4. 使用JndiTemplate实现InitialContext环境变量的配置,例如
<bean id="queueTarget" class="org.springframework.jndi.JndiObjectTargetSource">
    <property name="jndiName">
        <value>queue/testQueue</value>
    </property>
    <property name="jndiTemplate">
        <ref local="jndiTemplate"/>
    </property>
</bean>
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
    <property name="environment">
        <props>
            <prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
            <prop key="java.naming.provider.url">jnp://localhost:1099</prop>
            <prop key="java.naming.factory.url.pkgs">org.jboss.naming:org.jnp.interfaces</prop>
        </props>
    </property>
</bean>

 

你可能感兴趣的:(java,spring,bean,jboss)