Jersey restful任何訪問都404和接收json物件
阿新 • • 發佈:2019-01-01
這邊是使用Jersey2.5新增jar包如下圖:
我這邊出現404主要是因為jar包未自動載入。
支援引數傳json串,需新增jar包,並且在每個請求之前新增對json的支援
@ApplicationPath("/service") public class RESTApplication extends ResourceConfig{ public RESTApplication() { packages("corp.creditease.dianxiao.service.restful"); register(JacksonJsonProvider.class); register(LoggingFilter.class); } } 服務端:
@Path("/testService") public class TestService { @GET @Produces(MediaType.TEXT_PLAIN) public String test(){ return "testRestful"; }
@POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON}訪問地址為:) @Path("/doPost") public TestResult getSome(Test param) { System.out.println("server:----------"+ JSONObject.fromObject(param).toString()); return new TestResult(); }
get請求:localhost:8080/service/testService
post請求:localhost:8080/service/testService/doPost 引數為json{"":"","":""} 測試post需新增Content-Type:application/json
web.xml不需要進行什麼配置。
jersey API地址:https://jersey.java.net/