我在 Spring 中注入(inject)了三个分层层 - 休息、业务逻辑和数据库操作。 BL 和 DAO 的 Junit 测试工作正常,而其余部分只能注入(inject)业务逻辑 ioc 层。
我的junit测试晚餐课:
import org.springframework.test.AbstractTransactionalSpringContextTests;
public class AbstractTest extends AbstractTransactionalSpringContextTests {
protected static final String path = "config/spring/applicationContext.xml";
/**
* Disabled autowire by type
* Disabled dependency check
*/
public AbstractTest() {
super();
this.setAutowireMode(AUTOWIRE_BY_NAME);
this.setDependencyCheck(false);
}
@Override
protected String[] getConfigLocations() {
return new String[] {
path
};
}
}
所以 - 其余调用业务逻辑,这调用数据库操作。数据库调用的业务逻辑中出现空指针异常。
更多信息示例: REST:getUser(id) 调用 BL: getUserBO(id) 调用 DAO: getUserDAO(id)
在 getUserBO 方法中的 getUserDAO 上抛出空指针。这种情况仅发生在正在部署的 junit 测试中。
最佳答案
你定义了数据源bean吗?没有更多详细信息(例如堆栈跟踪、应用程序上下文文件等),这是我的最佳猜测...
关于java - Spring 和 Struts2 REST - junit 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1487364/