Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Web services SpringWebService客户端-创建问题_Web Services_Spring_Jaxb2 - Fatal编程技术网

Web services SpringWebService客户端-创建问题

Web services SpringWebService客户端-创建问题,web-services,spring,jaxb2,Web Services,Spring,Jaxb2,我是新来的春天,所以我道歉,如果这似乎是显而易见的。我正在尝试创建一个JUnit测试用例来调用我的webservice。我想我终于明白了我应该做的事情的要点,但是不断地出错。我有一个基本的测试课程: @RunWith(SpringJUnit4ClassRunner.class)<br> @ContextConfiguration(locations={"/test.xml"}) public class Tester { private WebServiceTemplate serv

我是新来的春天,所以我道歉,如果这似乎是显而易见的。我正在尝试创建一个JUnit测试用例来调用我的webservice。我想我终于明白了我应该做的事情的要点,但是不断地出错。我有一个基本的测试课程:

@RunWith(SpringJUnit4ClassRunner.class)<br>
@ContextConfiguration(locations={"/test.xml"})
public class Tester {
private WebServiceTemplate service;
@Test
public void testEntityWS(){
    EntityDetailsRequest request = new ObjectFactory().createEntityDetailsRequest();
    EntityDetailsRequest.CallerReference callerReference = new EntityDetailsRequest.CallerReference();
    callerReference.setAuthenticationToken("ASD345F8F9");
    callerReference.setRequestingEntity(123456l);
    request.setCallerReference(callerReference);
    request.setSchemaVersion(new Float(1.0));
    request.setLegalReferenceNumberType("123456");

    EntityDetailsResponse response = (EntityDetailsResponse) service.marshalSendAndReceive(request);
    System.out.println("DONE");
    System.out.println(response.getEntityNumber());
}

这是第34行:EntityDetailsResponse响应=(EntityDetailsResponse)服务;“服务”对象为空。所以在我看来,“服务”并不是由Spring配置初始化的。我不知道为什么-我配置的时候做错了什么吗?好吧-所以我想我找到了答案。我把'@Autowired'放在“service”属性和tadaa之上。我的问题是:有必要把这个注释放进去吗?在这个主题上…有必要添加“@ContextConfiguration”注释吗。我不能在我的项目中设置它,让java/Spring知道在哪里查找吗?
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oxm="http://www.springframework.org/schema/oxm"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-1.5.xsd">

<oxm:jaxb2-marshaller id="Jaxb2.marshaller" contextPath="za.co.discovery.finance.card.xml"/>

<bean class="org.springframework.ws.client.core.WebServiceTemplate" id="entityService">
    <property name="defaultUri" value="http://localhost:7001/entities/services/entityWebservice"/>
    <property name="marshaller" ref="Jaxb2.marshaller"/>
    <property name="unmarshaller" ref="Jaxb2.marshaller"/>
</bean>

<bean class="za.co.discovery.services.TestEntitiesWS" id="testEntitiesWS">
    <property name="service" ref="entityService"/>
</bean>
java.lang.NullPointerException
    at Tester.testEntityWS(Tester.java:34)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:71)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:199)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:62)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)