java後臺 webService服務端
需要引用的包
com.microsoft.sqlserver mssql-jdbc 6.4.0.jre8編寫一個service介面
@WebService(name = “CommonService”, // 暴露服務名稱(當前類的名稱)
targetNamespace = “http://service.shippingsystem.newinfo.com/”// 名稱空間,一般是介面的包名倒序(當前類的路徑)
)
public interface CommonService {
@WebMethod //標識是一個WebService的方法
@WebResult(name = “String”, targetNamespace = “”)
public String sayHello(@WebParam(name = “userName”) String name);
}
service實現類
@WebService(serviceName = “CommonService”, // 與service介面中指定的name一致
targetNamespace = “http://service.shippingsystem.newinfo.com/”, // 與介面中的名稱空間一致,一般是介面的包名倒
endpointInterface = “com.neinfo.shippingsystem.service.CommonService”// service介面地址
)
@Component
public class CommonServiceImpl implements CommonService {
@Override
public String sayHello(String name) {
System.out.println(name);
return “Hello ,” + name;
}
}
WebService的工具類
@Configuration
public class CxfConfig {
@Autowired private Bus bus; @Autowired CommonService commonService; /** JAX-WS **/ @Bean public Endpoint endpoint() { EndpointImpl endpoint = new EndpointImpl(bus, commonService); endpoint.publish("/CommonService"); return endpoint; }
}