1.Jetty嵌入到Spring项目
try {
Server server = new Server(8080);
WebAppContext context = new WebAppContext();
context.setContextPath("/test");
context.setDescriptor(filePath + "/conf/web.xml"); // 指定web.xml配置文件
context.setResourceBase(filePath + "/conf/");// 指定webapp目录
context.setParentLoaderPriority(true);
server.setHandler(context);
server.start();
server.join();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
2.Jetty添加Filter的方式有两种
1.类似Tomcat,在web.xml中指定过滤器,但需要确定配置文件WEB-INF/web.xml 存在于webapp根目录