我正在尝试将内置的 Restful WebServices 与 JBoss AS 7 一起使用。我的 web.xml 是..
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
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_2_5.xsd"
version="2.5">
</web-app>
我的应用程序类是...
package com.robert;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import java.util.HashSet;
import java.util.Set;
@ApplicationPath("/services")
public class HelloWorld extends Application {
private Set<Object> singletons = new HashSet<Object>();
public HelloWorld() {
singletons.add(new Library());
}
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<Class<?>>();
classes.add(Library.class);
return classes; //To change body of overridden methods use File | Settings | File Templates.
}
@Override
public Set<Object> getSingletons() {
return singletons;
}
}
我的课是
import javax.ws.rs.*;
@Path("/library")
public class Library {
@GET
@Path("/books")
public String getBooks() {
return "this is all your books";
}
@GET
@Path("/book/{isbn}")
public String getBook(@PathParam("isbn") String id) {
// search my database and get a string representation and return it
return "Its a good book; I read it";
}
@PUT
@Path("/book/{isbn}")
public void addBook(@PathParam("isbn") String id, @QueryParam("name") String name) {
System.out.println("Adding book "+name);
}
@DELETE
@Path("/book/{id}")
public void removeBook(@PathParam("id") String id ){
System.out.println("Removing book "+id);
}
}
但是,当我启动 JBoss AS7 时,WebService 永远不会启动。我在 JBoss 管理页面中看不到它,在
http://foobar:8080/MyWar/services/library/books