【问题标题】:Testing JNDI Spring Websphere Outside the Container在容器外测试 JNDI Spring Websphere
【发布时间】:2011-05-25 01:39:09
【问题描述】:

我通过 jndi 查找数据源信息,成功地在 weblogic 服务器之外测试了一些 DAO。我已经搜索了一个与 websphere 类似的选项,并且还必须遇到一个不涉及在应用程序中的某个位置或类似位置硬编码用户名和密码的解决方案。现在我的 jndi 设置在 spring 中是这样的:

com.ibm.websphere.naming.WsnInitialContextFactoryiiop://localhost:2809道具> 属性> 豆> PeopleAppDS豆>

我已经测试了 jndi 连接,当应用程序加载到 websphere 时它正在工作。例如,我希望能够在加载应用程序之前测试 eclipse 中的 daos。任何帮助将不胜感激。

这是测试用例的详细信息。

-------BaseTestCase.java--------

import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations= {"file:data-access-config.xml"})
public class BaseTestCase {

}

-----PersonDaoTest.java----------------

import static org.junit.Assert.assertNotNull;

import java.util.List;<br>

import org.junit.Test;<br>
import org.springframework.beans.factory.annotation.Autowired;

import ....dao.PersonDao;<br>
import ....domain.Person;<br>

public class PersonDaoTest extends BaseTestCase {

    @Autowired
    private PersonDao personDao;


    @Test
    public void findByName() {
        List<Person>  people = personDao.listByName("j%", false, "userId");
        assertNotNull(people);
    }
}

【问题讨论】:

    标签: spring junit websphere jndi


    【解决方案1】:

    正确的做法是使用默认的 DriverManagerDataSource 的 JNDI 数据源。如果在容器中运行,Spring 将使用命名数据源;如果查找失败,它将使用非 JNDI 数据源。

    【讨论】:

    • 我不确定我是否理解您在此处所说的内容。我认为 DriverManagerDataSource 需要将连接信息存储在应用程序或某处的某个属性文件中。我面临的一个限制是我不能为这个应用程序做到这一点。
    • 是的,查看 JNDI 数据源。它允许你有一个默认值。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-16
    • 2010-12-09
    相关资源
    最近更新 更多