2014-09-02 2 views
2

나는 JABX 사용하여 WSDL에서 도메인 클래스를 생성하고 다음과 같은 클라이언트 구현했습니다 :봄 웹 서비스 요청

@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; 
    } 
} 

그리고 테스트 : 나는 URI를 설정하지 않으면

@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); 
    } 
} 

내가 얻을 : java.lang.IllegalArgumentException: 'uri' must not be empty; 나는 마샬을 설정하지 않으면

내가 얻을 다음 WebServiceConfig의 구성과 같은 IllegalStateException: No marshaller registered. Check configuration of WebServiceTemplate.

그 콩를 autowire에도 불구하고, 작동하지 않는 것은 null가 아닌.

정말 감사드립니다. 감사.

+0

여전히 StackOverflow를 모니터링하고있는 경우라면 궁극적 인 해결책은 무엇입니까? 게시 할 수 있습니까? 고마워 – sairn

답변

2

AccountEndpoint에서 @Service 주석을 제거해야합니다. Bean이 구성 클래스에 작성됩니다.