我们正在使用泽西弹簧3将泽西1.x的一些数据服务从泽西1.x迁移到泽西2.x.
我们有一些继承自JerseyTest的测试类.其中一些类使用未在web.xml文件中指定的自定义applicationContext.xml文件.
在Jersey 1.x中,扩展JerseyTest的测试类可以使用WebappDescriptor.Builder调用超级构造函数,可以传递上下文参数来设置或覆盖应用程序上下文路径.
例如
public MyTestClassThatExtendsJerseyTest()
{
super(new WebAppDescriptor.Builder("com.helloworld")
.contextParam( "contextConfigLocation", "classpath:helloContext.xml")
.servletClass(SpringServlet.class)
.contextListenerClass(ContextLoaderListener.class)
.requestListenerClass(RequestContextListener.class).build());
}
Run Code Online (Sandbox Code Playgroud)
如何用Jersey 2.x实现同样的目标?
我已经梳理了API文档,用户指南和一些来源,但无法找到答案.
谢谢.
此问题是从上一个问题指定自定义应用程序上下文的后续问题.
我们正在使用泽西弹簧3将泽西1.x的一些数据服务从泽西1.x迁移到泽西2.x.
我们有一些继承自JerseyTest的测试类.其中一些类使用未在web.xml文件中指定的自定义applicationContext.xml文件.
出于对象模拟的目的,我们将在Jersey资源中模拟一些组件.
在Jersey 1.x中,我们可以通过模拟应用程序上下文文件中的对象
<bean id="mockBean" class="org.easymock.EasyMock"
factory-method="createStrictMock" autowire="byName">
<constructor-arg index="0" value="com.xxx.xxx.ClassToMock" />
</bean>
Run Code Online (Sandbox Code Playgroud)
并按如下方式检索这些模拟的实例
ClassToMock obj = (ClassToMock)ContextLoader
.getCurrentWebApplicationContext()
.getAutowireCapableBeanFactory()
.getBean("mockBean");
Run Code Online (Sandbox Code Playgroud)
如何使用Jersey 2.x使用jersey-spring3实现同样的目标?
我已经梳理了API文档,用户指南和一些来源,但无法找到答案.
谢谢.
编辑:
我们将在JAX-RS资源中使用模拟bean.我们的服务接口属于@Autowired我们的资源.
例如
@Path(ProductResource.RESOURCE_PATH)
@Component
@Scope("prototype")
public class ProductResource
extends GenericResource<Product, BaseModel> {
/*
* Members
*/
public static final String RESOURCE_PATH = "product/";
@Autowired
protected ProductService productService;
...
Run Code Online (Sandbox Code Playgroud)
我们想要模拟并设定对这些服务的期望.
例如
<bean id="productService" class="org.easymock.EasyMock"
factory-method="createStrictMock">
<constructor-arg index="0"
value="com.xxx.xxx.service.ProductService" />
</bean>
Run Code Online (Sandbox Code Playgroud)