Java 具有空URI和空封送器的SpringWeb服务请求
我使用JABX从WSDL生成了域类,并实现了以下客户端:Java 具有空URI和空封送器的SpringWeb服务请求,java,spring,web-services,jdbc,Java,Spring,Web Services,Jdbc,我使用JABX从WSDL生成了域类,并实现了以下客户端: @Service public class AccountEndpoint extends WebServiceGatewaySupport { private static final Logger logger = Logger.getLogger(String.valueOf(AccountEndpoint.class)); public AccountEndpoint() { } public
@Service
public class AccountEndpoint extends WebServiceGatewaySupport {
private static final Logger logger = Logger.getLogger(String.valueOf(AccountEndpoint.class));
public AccountEndpoint() {
}
public GetAccountResponse getAccount(long accountAgency, long accountNumber) {
GetAccountRequest request = new GetAccountRequest();
request.setAccountAgency(accountAgency);
request.setAccountNumber(accountNumber);
GetAccountResponse response = (GetAccountResponse)
getWebServiceTemplate().marshalSendAndReceive(request);
return response;
}
}
我是这样配置的:
@Configuration
@ComponentScan(basePackages = {"org.myco.mypro.core"})
public class WebServiceConfig {
@Bean
public Jaxb2Marshaller marshaller() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("org.myco.mypro.webservices");
return marshaller;
}
@Bean
public AccountEndpoint accountEndpoint(Jaxb2Marshaller marshaller) {
AccountEndpoint client = new AccountEndpoint();
client.setDefaultUri("http://localhost:11000/ws");
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
return client;
}
}
和测试:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = WebServiceConfig.class)
public class AccountEndpointTest extends TestCase {
@Autowired
private AccountEndpoint accountEndpoint;
public void setUp() throws Exception {
super.setUp();
}
@Test
public void testGetAccount() throws Exception {
accountEndpoint.setDefaultUri("http://localhost:11000/ws");
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("org.myco.mypro.webservices");
accountEndpoint.setMarshaller(marshaller);
accountEndpoint.setUnmarshaller(marshaller);
GetAccountResponse response = accountEndpoint.getAccount(12, 16);
assertNotNull(response);
}
}
如果我没有设置获取的URI:java.lang.IllegalArgumentException:“URI”不能为空
如果我没有设置封送拆收器,我会得到:IllegalStateException:没有注册封送拆收器。检查WebServiceTemplate的配置。
这就像WebServiceConfig中的配置不工作一样,尽管bean autowired不是null
我真的很感谢你的帮助。谢谢。您应该从AccountEndpoint中取出@Service注释。
bean是在配置类中创建的。如果您仍在监视StackOverflow,您的最终解决方案是什么?你能邮寄吗?谢谢