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

}

猜你喜欢

转载自blog.csdn.net/weixin_44276894/article/details/85258771