5

正如问题所暗示的那样,我有一个简单的 java 应用程序(又名“简单主程序”),它需要初始化一个休眠连接,其信息位于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
}

那么有没有一种简单的方法可以从 xml 文件创建 InitialContext 呢?我对手动解析文件不感兴趣,我可以自己做。

4

0 回答 0