JAX RS MediaType annotation values must be of the

2019-08-03 07:36发布

问题:

I am supposed to learn restful services using Java and JAX RS. I am trying to compile the following code, however I receive an error stating: annotation values must be of the form 'name=value'.

The code is in principle correct, it is equivalent with http://www.vogella.com/tutorials/REST/article.html

import javax.ws.rs.*;
import javax.ws.rs.core.*;
import javax.xml.ws.Response;
import java.io.IOException;

@Path("/")
public class WebResource {

    @GET
    @Produces(
            MediaType.APPLICATION_XML,
            MediaType.APPLICATION_ATOM_XML)
    @XmlHeader("<?xml-stylesheet type='text/xsl' href='=static/styles/atom2html.xsl' ?>")
    public Feed getFeed() {
        return FeedController.getInstance().getFeed();
    }
}

回答1:

You are providing several MediaType for the @Produces annotation so you need to put them in an array:

@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML})


标签: java rest jax-rs