Ste*_*dis 5 java jndi initial-context
正如问题所暗示的,我有一个简单的java应用程序(又名“简单的主”),需要初始化一个hibernate连接,其信息位于context.xml.
经过大量搜索和一些技巧后,我得出以下结论:
public static void main(String[] args) {
//JNDI provider is needed and RMI registry has one...
try {
java.rmi.registry.LocateRegistry.createRegistry(1099);
System.out.println("RMI registry ready.");
} catch (Exception e) {
System.out.println("Exception starting RMI registry:");
e.printStackTrace();
}
new InitialContext().readContextXml("context.xml");//of course there is nothing like that. But is there an equivalent?
String result = thatWillConnectWithHibernate();
System.out.println(result);
}
private static String thatWillConnectWithHibernate() {
//does stuff
}
Run Code Online (Sandbox Code Playgroud)
那么有没有一种简单的方法可以从 xml 文件创建一个 InitialContext 呢?我对手动解析文件不感兴趣,我可以自己做。
| 归档时间: |
|
| 查看次数: |
297 次 |
| 最近记录: |