1. 写一个jndi.porperties
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=192.168.10.172:1100
jnp.disableDiscovery=false
注: 这个org.jnp.interfaces.NamingContextFactory是Jboss配置文件中配的
2.在程序中可以使用
例如:
public static void main(String[] args) throws NamingException, CreateException, FileNotFoundException, IOException {
// TODO Auto-generated method stub
Properties props = new Properties();
props.load(new BufferedInputStream(new FileInputStream("jndi.properties")));
Context ctx = new InitialContext(props);
Object obj = ctx.lookup("TestSession");
TestSessionHome home = (TestSessionHome) javax.rmi.PortableRemoteObject.narrow(obj, TestSessionHome.class);
TestSession test = home.create();
System.out.println(test.foo());
}
3.可以根据我的文件加入hibernate的SessionFactory到Jboss的JNDI中
4.这样可以使用hiberante Tools 生成的一些 Home的代码了。
阅读(2209) | 评论(0) | 转发(0) |