SpringBoot WebService 及 注意项

简介: SpringBoot WebService 及 注意项

SpringBoot WebService 源代码:https://gitee.com/VipSoft/VipWebService

SpringBoot 版本 <version>2.3.0.RELEASE</version>
<cxf.version>3.3.1</cxf.version>
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-core</artifactId>
    <version>${cxf.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-frontend-jaxws</artifactId>
    <version>${cxf.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-transports-http</artifactId>
    <version>${cxf.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-transports-http-jetty</artifactId>
    <version>${cxf.version}</version>
</dependency>
package com.vipsoft.service;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
@WebService(name = "DemoWebService", // 暴露服务名称,不指定就会使用类名
        targetNamespace = "http://service.his.vipsoft.com"// 与接口中的命名空间一致,一般是接口的包名倒 不加这个,SOAPUI 获取不到地址
)
public interface IDemoWebService {
    @WebMethod(action = "http://ws.vipsoft.com/sayHello") //有些集成平台,如果不加 action 会调不成功
    public String sayHello(@WebParam(name = "arg") String arg);
}
package com.vipsoft.service.impl; 
import com.vipsoft.service.IDemoWebService;
import org.springframework.stereotype.Component;
import javax.jws.WebService;
import java.util.Date;
@Servicepublic class DemoWebServiceImpl implements IDemoWebService {
    @Override
    public String sayHello(String arg) {
        return arg + ",现在时间:" + "(" + new Date() + ")";
    }
}
package com.vipsoft.web.config;
import com.vipsoft.service.IDemoWebService;
import com.vipsoft.service.impl.DemoWebServiceImpl;
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.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.xml.ws.Endpoint;
@Configuration
public class CxfConfig {
    @SuppressWarnings("all")
    @Bean(name = "cxfServlet")  //不加可能会报错
    public ServletRegistrationBean cxfServlet() {
        return new ServletRegistrationBean(new CXFServlet(), "/ws/*");
    }
    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }
    @Bean
    public IDemoWebService demoService() {
        return new DemoWebServiceImpl();
    }
    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), demoService()); //绑定要发布的服务
        endpoint.publish("/api"); // 暴露webService api,用在资源访问
        return endpoint;
    }
}

 

Error loading [http://localhost:9090/ws/api?wsdl]: java.lang.Exception: Load of url [http://localhost:9090/ws/api?wsdl] was aborted

WebService 不能使用 localhost 访问,可以通过 ipconfig 查看本机IP,使用IP进行访问

http://192.168.1.216:9090/ws/api?wsdl

 

 

目录
相关文章
|
5月前
|
Java 数据处理
【十二】springboot整合WebService
【十二】springboot整合WebService
191 0
|
5月前
|
XML 存储 Java
SpringBoot集成WebService
SpringBoot集成WebService
288 1
|
5月前
|
Java
【十三】springboot整合WebService关于传参数
【十三】springboot整合WebService关于传参数
102 0
|
5月前
|
Java 数据库连接 Apache
SpringBoot整合CXF实现WebService
SpringBoot整合CXF实现WebService
319 0
|
Java 容器
springboot中简单创建webservice服务
不添加配置类也可以在springboot的启动类了里面发布服务,但是那样的话就不是ioc托管的了,在服务里面就不能注入其他IOC容器里面的对象
|
前端开发 Java
springboot发布webservice
springboot发布webservice
|
Java Maven
Springboot整合CXF发布WebService
Springboot整合CXF发布WebService
Springboot整合CXF发布WebService
springboot配置webservice服务发布
springboot配置webservice服务发布
370 0
|
Java
SpringBoot + cxf 调用 webService
SpringBoot + cxf 调用 webService
727 0