1. 程式人生 > >Spring boot 中使用webservice

Spring boot 中使用webservice

自己寫完一個demo後,測試時得不到wsdl文件,下面貼上自己的程式碼

首先是釋出服務用的介面
package com.pudding.tcs.ctrip.testservice;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public interface TestService {
@WebMethod
public String test(String param);
}

接下來是介面實現
package com.pudding.tcs.ctrip.testservice;
public class TestServiceImpl implements TestService {
@Override
public String test(String param) {
return "param="+param;
}
}
再接下來是配置類用於釋出服務:
package com.pudding.tcs.ctrip.config;
import javax.xml.ws.Endpoint;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.pudding.tcs.ctrip.testservice.TestService;
import com.pudding.tcs.ctrip.testservice.TestServiceImpl;
@Configuration
public class TestConfig {
@Bean
public ServletRegistrationBean dispatcherServlet() {
return new ServletRegistrationBean(new CXFServlet(), "/soap/*");
}

@Bean(name = Bus.DEFAULT_BUS_ID)
public SpringBus springBus() {
return new SpringBus();
}

@Bean
public TestService testService() {
return new TestServiceImpl();
}

@Bean
public Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(springBus(), testService());
endpoint.publish("/test");
return endpoint;
}

}
按道理講這樣配置完之後我啟動伺服器,在位址列輸入http://localhost:8080/soap/test?wsdl是可以顯示wsdl文件的。可是現在輸完地址瀏覽器沒有任何反應。不知道問題出在了哪裡。

還望各路神仙給小弟解答一下