restful-xml

@Path("student")
public class StudentXMLService {


// <student>
// <name>xiewenbo</name>
// <number>13061012</number>
// </student>
@GET
@Produces(MediaType.APPLICATION_XML)
public Student getStudentXML(){

Student student = new Student("xiewenbo","13061012");
return student;
}

}

public class StudentTest {


public static void main(String[] args) throws IOException {
        URI ServerURI=UriBuilder.fromUri("http://localhost/").port(9998).build();
    startServer(ServerURI);
        System.out.println("服务已启动,请访问:"+ServerURI);
    }    

    protected static SelectorThread startServer(URI serverURI) throws IOException {
        final Map<String, String> initParams = new HashMap<String, String>();
        initParams.put("com.sun.jersey.config.property.packages","com.ws.service.xml");
        System.out.println("Grizzly 启动中...");
        SelectorThread threadSelector = GrizzlyWebContainerFactory.create(serverURI, initParams);     
        return threadSelector;
    }  


}


你可能感兴趣的:(xml,String,Class,Path)