我想用两种方法设计邮政服务。方法名称将不同。这两种方法将采用不同的对象进行调用。但是,路径和生产/消费媒体类型必须相同。怎么做?请在下面找到此代码。它给出了异常,例如“在部署到weblogic中时,资源模型具有HTTP方法POST的模棱两可(子)资源方法,并由Java方法中的“ @Consumes”和“ @Produces”注释定义的输入mime类型”。 >
package com.adac.rest.service; import javax.ws.rs.Path; import javax.ws.rs.POST; import javax.ws.rs.Consumes; import javax.ws.rs.Produces; import com.adac.rest.model.Response; import com.adac.rest.model.SalesData; import com.adac.rest.model.Tax; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; @Path("/rest") public class StageDataLoadingService { @POST @Path("/dataloading") @Consumes("application/json") @Produces("application/json") public String resourceMethodPUTSalesData(SalesData sd) throws Exception { System.out.println("This method called with Sales Data"); Response resp = new Response(); resp.setStatuscode("0"); resp.setStatusmessage("Success"); ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); String json_resp = mapper.writeValueAsString(resp); String str1 = mapper.writeValueAsString(sd); System.out.println(str1); //String sd1 = mapper.writeValueAsString(sd); //System.out.println(sd1); // JsonNode jsonNodeRoot = mapper.readTree(json_resp); return json_resp; } @POST @Path("/dataloading") @Consumes("application/json") @Produces("application/json") public String resourceMethodPUTTax(Tax tax) throws Exception { System.out.println("This method called with Tax"); Response resp = new Response(); resp.setStatuscode("0"); resp.setStatusmessage("Success"); ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); String json_resp = mapper.writeValueAsString(resp); String str1 = mapper.writeValueAsString(tax); System.out.println(str1); return json_resp; } }
此外,为您建议的设计建议web.xml和weblogic.xml配置。
当前的web.xml是:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>ADACStageDataLoadingService</display-name> <servlet> <servlet-name>rest.application.config.ApplicationConfig</servlet-name> </servlet> <servlet-mapping> <servlet-name>rest.application.config.ApplicationConfig</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app>
和weblogic.xml是:
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app
xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.9/weblogic-web-app.xsd">
<wls:weblogic-version>12.2.1.3</wls:weblogic-version>
<wls:context-root>ADACStageDataLoadingService</wls:context-root>
<wls:library-ref>
<wls:library-name>jax-rs</wls:library-name>
<wls:specification-version>2.0</wls:specification-version>
<wls:exact-match>false</wls:exact-match>
</wls:library-ref>
</wls:weblogic-web-app>
我想用两种方法设计邮政服务。方法名称将不同。这两种方法将采用不同的对象进行调用。但是路径和生产/消费媒体类型将...
[开发API时,我建议您遵循其余的最佳做法: