2016-02-29 67 views
1

我使用Spring Boot 1.3。*構建合同的第一個Web服務。我看了How to use WSDL with spring-boot?這個問題的答案。這工作正常Spring Boot wsdl first - 將url更改爲wsdl

@EnableWs 
@Configuration 
public class WebServiceConfig extends WsConfigurerAdapter { 
@Bean 
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) { 
    MessageDispatcherServlet servlet = new MessageDispatcherServlet(); 
    servlet.setApplicationContext(applicationContext); 
    servlet.setTransformWsdlLocations(true); 
    return new ServletRegistrationBean(servlet, "/ws/*"); 
} 

//http://localhost:8080/ws/services.wsdl --bean name is set to 'services' 
@Bean(name = "services") 
public Wsdl11Definition defaultWsdl11Definition() { 
    SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition(); 
    wsdl11Definition.setWsdl(new ClassPathResource("/schema/MyWsdl.wsdl")); //your wsdl location 
    return wsdl11Definition; 
} 
} 

我的wsdl現在位於http://localhost:8080/ws/services.wsdl。問題是,這將是此Web服務的消費者的應用需要WSDL URL寫爲

http://localhost:8080/ws/services?wsdl 

我怎樣才能做到這一點?

+0

您會使用類似urlrewrite的內容嗎?我應該提供解決方案嗎? – sgpalit

+0

這可能會訣竅,所以是的。 – baron5

+0

你使用tomcat容器嗎? http://tuckey.org/urlrewrite/你可以做這些設置嗎?否則它不會工作:( – sgpalit

回答

0

要urlrewrite配置爲豆檢查這個tuckey-url-rewrite-filter-java-class-configuration

這將在後端和用戶轉發將不會收到通知。在您的urlrewrite.xml中添加此規則

<rule> 
    <from>/ws/services?wsdl</from> 
    <to>/ws/services.wsdl</to> 
</rule> 
+0

我會試試這個,謝謝!會讓你知道什麼時候/ if我成功了。 – baron5

+1

我不得不使用web.xml來完成它,但它可以工作。所以這是一個有效的解決方案,謝謝。 – baron5