【发布时间】:2015-06-02 21:02:32
【问题描述】:
CXF 肥皂应用,使用以下版本:
springBootVersion = 1.2.3.RELEASE
springVersion = '4.1.6.RELEASE'
cxfVersion = '3.1.0'
junitVersion = '4.12'
我有一个请求范围的 spring bean:
@Component
@Scope( value=WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS )
public class RequestScopedClass
我在 CXF 端点实现中从 ApplicationContext 动态获取:
@Component
@WebService(endpointInterface = "ch.xyz.PaymentServiceInterface" )
public class PaymentServiceImpl implements PaymentServiceInterface
{
...
RequestScopedClass rsc = appCtxt.getBean( RequestScopedClass.class );
rsc.doSomething();
我的目标是通过模拟连接到侦听器端口等的客户端来测试soap服务的前端,确保执行带有拦截器链(包括我的自定义拦截器)的整个cxf堆栈。我设法通过包含
来设置此配置org.apache.cxf:cxf-rt-transports-http-jetty
在测试设置中的依赖和启动端点:
String address = "http://0.0.0.0:8080/";
myEndpoint = Endpoint.publish( address, new PaymentServiceImpl() );
运行测试会在调用 rsc.doSomething() 时抛出 BeanCreationException:
Error creating bean with name 'scopedTarget.requestScopedEnvironment': Scope 'request' is not active ...
如果我将 proxyMode 更改为其他三个可能性之一,则在从 appCtxt 获取 bean 时已经引发了相同的异常。
测试由
注释@RunWith( SpringJUnit4ClassRunner.class )
@ContextConfiguration( classes = {
...,
RequestScopedClass.class
}
)
@WebAppConfiguration
如果应用程序是通过命令行上的“gradle bootrun”启动的,并且soap请求由chrome postman应用程序完成,那么一切都很好,我得到了预期的soap响应。
在单元测试中执行 cxf soap 服务器时,如果存在有效的请求范围,我该怎么办?
【问题讨论】:
标签: web-services unit-testing soap scope cxf