简体   繁体   中英

Need xml bean's java representation in Spring4

How can i represent the following code snippet in java, my project is using Spring4 and i need to convert the same. Any help would be much appreciated. Thanks in advance!

<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
  <property name="environment">
     <props>
        <prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
        <prop key="java.naming.provider.url">t3://localhost:7001</prop>
     </props>
  </property>

Here's the equivalent Java config. Add it to your @Configuration class:

@Bean
public JndiTemplate jndiTemplate() {
    Properties props = new Properties();
    props.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    props.setProperty(InitialContext.PROVIDER_URL, "t3://localhost:7001");
    return new JndiTemplate(props);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM