我正在尝试使用Jetty WebAppcontext编写REST服务,我在下面 代码,但我得到503。不确定我缺少什么。
public static void main(String[] args) throws Exception {
Server server = new Server(8081);
HandlerCollection handlers=new HandlerCollection();
String resourceBase = WebServer.class.getClassLoader().getResource(".").toString()+"../../src/main/webapp";
WebAppContext webAppContext = new WebAppContext(resourceBase,"/");
System.out.println(" resourceBase "+resourceBase);
handlers.addHandler(webAppContext);
server.setHandler(handlers);
server.start();
System.out.println("Started");
server.join();
}
Web.xml
<servlet>
<servlet-name>Jersey</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.app.server.WebApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
WebApplication代码
public class WebApplication extends ResourceConfig {
public WebApplication(){
System.out.println("initialized");
register(JacksonJaxbJsonProvider.class);
packages("com.app.rest.services");
}
}
服务是
@Path("/get")
public class Get {
private static final Logger logger = LogManager.getLogger(Get.class);
@GET
@Produces(MediaType.TEXT_PLAIN)
public String get() {
return "Yes";
}
}
以http://localhost:8081/rest/get拨打电话时,我得到503。 我已经尝试了很多,但是仍然遇到相同的错误。请让我知道我在想什么。
谢谢