WebService服务端框架:jersey
WebService调用方式:jersey、http、spring RestTemplate
Server:
@Configurationpublic class ApplicationConfig { @Named static class JerseyConfig extends ResourceConfig { public JerseyConfig() { this.packages("com.lenovo.li.content.controllers"); } } @Bean public ObjectMapper objectMapper() { ObjectMapper objectMapper = new ObjectMapper(); return objectMapper; }}
Pom
org.springframework.boot spring-boot-starter-jersey
Controller
@Named@Path("/Test")public class RestController { @POST @Path("/get/{url}") @Produces(MediaType.APPLICATION_JSON) public Test getTestContent(@PathParam("url") final String url, @RequestBody Context context) throws JsonParseException, JsonMappingException, IOException { } @PUT @Path("/update/{url}") @Produces(MediaType.APPLICATION_JSON) public Test updateTestContent(@PathParam("url") final String url, @RequestBody Page page) throws JsonParseException, JsonMappingException, IOException { }}
Client
public class TestClient{ @Autowired RestTemplate restTemplate; public String getTestContent(String name, Context context) { ResponseEntityresponse = restTemplate.postForEntity(url, context,String.class); return response.getBody(); }}
ClientXml