Spring 使用REST根资源类作为接口,获取;无操作匹配请求“;

Spring 使用REST根资源类作为接口,获取;无操作匹配请求“;,spring,rest,tomcat7,cxf,m2eclipse,Spring,Rest,Tomcat7,Cxf,M2eclipse,问题:根资源类定义为与所有注释的接口。CXFServlet无法查看impl类上的POST操作,尽管它是在接口上定义的当所有注释都复制到impl类中时,它工作正常。 注意:仅在界面上定义GET时,GET工作正常,只有POST引起了问题 @Path("foo/") public interface TestService { @Path("foo/{id}") @GET @Produces("text/plain") public String getIt(Strin

问题:根资源类定义为与所有注释的接口。CXFServlet无法查看impl类上的POST操作,尽管它是在接口上定义的当所有注释都复制到impl类中时,它工作正常。

注意:仅在界面上定义GET时,GET工作正常,只有POST引起了问题

@Path("foo/")
public interface TestService {
    @Path("foo/{id}")
    @GET
    @Produces("text/plain")
    public String getIt(String id);

@Path("foo")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ElementClass(response = Bar.class)
public Response createStuff(@Context MessageContext context,
        Bar bar);
}

}

Beans.xml {



我自己解决了这个问题。在imll类方法中,不要用注释重新声明参数

在Impl类内部的这个代码段中

@Override
public Response createStuff(*@Context* MessageContext context,
        Bar bar) {

我不必要地使用了@Context注释,这会将其丢弃。一旦我从impl类中删除注释,它就可以正常工作。正确地说,当您在接口中指定方法参数时,为什么还要重新修饰它。

您如何发送响应?您可以更改
@products吗(MediaType.APPLICATION_JSON)
@products(“text/plain”)
<jaxrs:server id="testService" address="/test">
        <jaxrs:serviceBeans>
            <ref bean="testservice1"/>
        </jaxrs:serviceBeans>
    </jaxrs:server>
    <bean id="testservice1" class="foo.bar.TestServiceImpl"/>
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    ……..
    </listener>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
Address: http://localhost:8080/<war-name>/test/foo/foo
Encoding: ISO-8859-1
Http-Method: POST
Content-Type: application/json
Headers: {Accept=[*/*], accept-encoding=[gzip,deflate,sdch], accept-language=[en-US,en;q=0.8], cache-control=[no-cache], connection=[keep-alive], Content-Length=[144], content-type=[application/json], host=[localhost:8080], origin=[chrome-extension://fdmmgilgnpjigdojojpjoooidkmcomcm], user-agent=[Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36]}
Payload: {
    "bar": {
        "create_time": "Fri Sep 20 17:51:40 PDT 2013",
        "update_time": "e0739141-1e8c-48ad-b8ad-410331b3dba3",
    }
}
INFO: Outbound Message
---------------------------
ID: 1
Response-Code: 404
Content-Type: text/xml
Headers: {Allow=[GET, OPTIONS, HEAD], Date=[Sat, 21 Sep 2013 19:13:05 GMT], Content-Length=[0]}
@Override
public Response createStuff(*@Context* MessageContext context,
        Bar bar) {