需求是我们的Java项目中需要和移动端对接接口 ,同时也需要和终端设备对接接口所以为了区分做了两个接口路径:
http://localhost:994/pbh/api app接口路径
http://localhost:994/pbh/terminal 终端接口路径
在配置文件中配置两套 Endpoint
package com.qckj.health.module.webService.config;
import com.qckj.health.module.webService.app.IPbhAppService;
import com.qckj.health.module.webService.app.PbhAppServiceImpl;
import com.qckj.health.module.webService.terminal.IPbhTerminalService;
import com.qckj.health.module.webService.terminal.IPbhTerminalServiceImpl;
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 {
@Bean
public ServletRegistrationBean creatDispatcherServlet() {
return new ServletRegistrationBean(new CXFServlet(), "/pbh/*");
}
@Bean(name = Bus.DEFAULT_BUS_ID)
public SpringBus springBus() {
return new SpringBus();
}
@Bean
public IPbhAppService demoService() {
return new PbhAppServiceImpl();
}
@Bean
public IPbhTerminalService terminalService() {
return new IPbhTerminalServiceImpl();
}
@Bean
public Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(springBus(), demoService());
endpoint.publish("/api");
return endpoint;
}
@Bean
public Endpoint endpoint1() {
EndpointImpl endpoint = new EndpointImpl(springBus(), terminalService());
endpoint.publish("/terminal");
return endpoint;
}
}
IPbhTerminalService 接口
package com.qckj.health.module.webService.terminal;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService(name = "TerminalService", // 暴露服务名称
targetNamespace = "http://app.webService.module.health.qckj.com"// 命名空间,一般是接口的包名倒序
)
public interface IPbhTerminalService {
public String getDistListByDictType(@WebParam(name = "in0") String jsonStr);
public String uploadTj_hebeilangfang(@WebParam(name = "in0") String jsonStr);
}
IPbhTerminalService 接口实现
package com.qckj.health.module.webService.terminal;
@WebService(serviceName = "TerminalService", // 与接口中指定的name一致
targetNamespace = "http://terminal.webService.module.health.qckj.com", // 与接口中的命名空间一致,一般是接口的包名倒
endpointInterface = "com.qckj.health.module.webService.terminal.IPbhTerminalService"// 接口地址
)
@Slf4j
public class IPbhTerminalServiceImpl implements IPbhTerminalService {
@Autowired
private UserService userService;
@Autowired
private QcTerminalUploadService qcTerminalUploadService;
@Autowired
private PhysicalUploadService physicalUploadService;
@Override
public String getDistListByDictType(String jsonStr) {
Map<String, Object> map = (Map<String, Object>) GsonUtil.fromJson(jsonStr);
return userService.getDistListByDictType(map);
}
}
DemoService 接口
package com.qckj.health.module.webService.app;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService(name = "DemoService", // 暴露服务名称
targetNamespace = "http://app.webService.module.health.qckj.com"// 命名空间,一般是接口的包名倒序
)
public interface IPbhAppService {
public String checkBasicInfo(@WebParam(name = "in0") String idcard);
public String uploadData(@WebParam(name = "in0") String type, @WebParam(name = "in1") String jsonStr1, @WebParam(name = "in2") String jsonStr2, @WebParam(name = "in3") String reservedPara1, @WebParam(name = "in4") String reservedPara2) throws Exception;
public String uploadManageData(@WebParam(name = "in0") String type, @WebParam(name = "in1") String jsonStr1, @WebParam(name = "in2") String reservedPara1, @WebParam(name = "in3") String reservedPara2) throws Exception;
public String uploadBasicInfo(@WebParam(name = "in0") String jsonStr1, @WebParam(name = "in1") String jsonStr2, @WebParam(name = "in2") String jsonStr3, @WebParam(name = "in3") String jsonStr4, @WebParam(name = "in4") String reservedPara1, @WebParam(name = "in5") String reservedPara2) throws Exception;
}
DemoService 接口实现
package com.qckj.health.module.webService.app;
@WebService(serviceName = "DemoService", // 与接口中指定的name一致
targetNamespace = "http://app.webService.module.health.qckj.com", // 与接口中的命名空间一致,一般是接口的包名倒
endpointInterface = "com.qckj.health.module.webService.app.IPbhAppService"// 接口地址
)
public class PbhAppServiceImpl implements IPbhAppService {
}