您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何从tomcat Webapp中的context.xml文件获取资源?

如何从tomcat Webapp中的context.xml文件获取资源?

关键字是:JNDI。中的资源context.xml不是“系统资源”,而是JNDI资源。尝试这个:

InitialContext ic = new InitialContext();
// that's everything from the context.xml and from the global configuration
Context xmlContext = (Context) ic.lookup("java:comp/env");
DataSource myDatasource = (DataSource) xmlContext.lookup("jdbc/MyDatasource");

// Now get a connection to see if everything is fine.
Connection con = ds.getConnection();
// reaching this point means everything is fine.
con.close();
其他 2022/1/1 18:17:44 有653人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶