在jUnit中设置JNDI数据源 [英] Setting up JNDI Datasource in jUnit

查看:623
本文介绍了在jUnit中设置JNDI数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置一些jUnit测试。我们的数据库由服务器使用JNDI连接。我们有一个xml描述了root.xml中的设置。如何设置jUnit以连接数据库?我宁愿让它只读取root.xml中的内容,但我仍然愿意将其设置为无效。

I am trying to set up some jUnit testing. Our database is connected by the server using JNDI. We have an xml describing the setup in root.xml. How do I set up jUnit to hook up to the database? I'd prefer to have it just read the the stuff off of root.xml, but I'm open to setting it up anyway that works.

推荐答案

我发现最好的方法是使用名为 Simple-Jndi

I found that the best way to do it is to use something called Simple-Jndi.

我将此添加到maven文件中:

I added this to the maven file:

    <dependency>
        <groupId>simple-jndi</groupId>
        <artifactId>simple-jndi</artifactId>
        <version>0.11.4.1</version>
        <scope>test</scope>
    </dependency>

您可以在此下载该软件包,下载包含说明手册。
http://code.google.com/p/osjava/downloads/detail?name=simple-jndi-0.11.4.1.zip&can=2&q=

You can download the the package here, the download contains an instruction manual. http://code.google.com/p/osjava/downloads/detail?name=simple-jndi-0.11.4.1.zip&can=2&q=

添加到项目后,您只需按照说明添加几个属性文件。

After adding to to your project you just have to add a couple of properties files, per the instructions.

但是,在添加依赖项后,我相信您可以以编程方式添加jndi资源,而不是使用属性文件。你做这样的事情:( new InitialContext())。rebind(datasource,myDatasource);

However, after you add the dependency, I believe you can add your jndi resources programmatically instead of using properties files. You do something like this: (new InitialContext()).rebind("datasource",myDatasource);

这篇关于在jUnit中设置JNDI数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆