📄 test6.java
字号:
/**
*
*/
package test;
import javax.naming.Context;
import javax.naming.NamingException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jndi.JndiCallback;
import org.springframework.jndi.JndiTemplate;
/**
* 演示JndiObjectFactoryBean的使用
*
* @author worldheart
*
*/
public class Test6 {
protected static final Log log = LogFactory.getLog(Test6.class);
public static void main(String[] args) {
ApplicationContext ac = new ClassPathXmlApplicationContext("test6.xml");
//获得JndiTemplate
JndiTemplate tq = (JndiTemplate)ac.getBean("jndiTemplate");
String jndiTemplateStr = new String("jndiTemplate");
final String jndiCallbackStr = new String("jndiCallbackStr");
try{
//将对象绑定到JNDI树上
tq.bind("jndiTemplate",jndiTemplateStr);
//打印出查找结果
log.info(tq.lookup("jndiTemplate"));
//从JNDI树上去除对象的绑定
tq.unbind("jndiTemplate");
tq.execute(new JndiCallback(){
public Object doInContext(Context ctx) throws NamingException {
ctx.bind("jndiCallback", jndiCallbackStr);
log.info(ctx.lookup("jndiCallback"));
ctx.unbind("jndiCallback");
return null;
}
});
} catch(NamingException ne){
log.error(ne);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -