如何在junit测试类中查找Jndi名称?我不想为junit使用单独的configration文件而不提供数据源属性?我特别需要在我的测试类中进行jndi查找。
How can I lookup Jndi name in junit test class? I do not want to use separate configration file for junit and not giving datasource properties? I specifically need to do jndi lookup in my test class.
推荐答案以下是来自官方Spring文档的引用 http://static.springsource / spring / docs / 3.1.x / spring-framework-reference / html / testing.html#mock-objects-jndi :
Here is a quote from the official Spring docs static.springsource/spring/docs/3.1.x/spring-framework-reference/html/testing.html#mock-objects-jndi:
org.springframework.mock.jndi包中包含JNDI SPI的实现,您可以使用它为测试套件或独立应用程序设置简单的JNDI环境。
The org.springframework.mock.jndi package contains an implementation of the JNDI SPI, which you can use to set up a simple JNDI environment for test suites or stand-alone applications.
从这个doc我使用Spring上下文配置类来声明一个数据源:
From this doc I use Spring context configuration class which declares a datasource:
@Configuration public class JndiDataConfig { @Bean public DataSource dataSource() throws Exception { Context ctx = new InitialContext(); return (DataSource) ctx.lookup("java:comp/env/jdbc/datasource"); } }更多推荐
Jndi使用spring在junit中查找
发布评论