JettyServer常常会作为内嵌的server,特别是在我们开发JavaEE的应用的时候,JettyServer+Hsqldb会大大的加快我们开发的速度,它广泛应用于针对webapplication的自动化单元测试中。
作为一个webapplication,如果没有WEB-INF目录和下面的web.xml,你的反应会是什么?如果是一个Struts2+ Spring的一个webapplication呢?
有的时候我们真的有这种需求,比如我要用一个jar包来发布一个功能简单的application,既有webservice又是RESTfull的,在希望它是一种很light的方式的同时又希望利用Struts+Spring来做,怎么办呢?
我们来看看一种甚至是web.xml都不需要的方式吧。
final ClassPathXmlApplicationContext originalContext =
new ClassPathXmlApplicationContext("accountServiceContext.xml");
Object o = originalContext.getBean("accountService");
//publish accountservice as a webservice with XFire
XFire xfire = XFireFactory.newInstance().getXFire();
ServiceFactory factory = new ObjectServiceFactory(xfire.getTransportManager(), null);
Service service = factory.create(AccountService.class);
service.setInvoker(new BeanInvoker(o));
xfire.getServiceRegistry().register(service);
try {
int port = Integer.parseInt(System.getProperty("port", "9999"));
server = new Server(port);
//build a webappContext without WEN-INF/web.xml
WebAppContext webApp = new WebAppContext();
webApp.setContextPath("/");
webApp.setBaseResource(Resource.newClassPathResource(""));
webApp.setConfigurations(new Configuration[0]);
webApp.addFilter(RedirectFilter.class, "/*", 1);
//org.apache.struts2.dispatcher.FilterDispatcher, let struts recongonize our actions
webApp.addFilter(FilterDispatcher.class, "/*", 1).setInitParameter("actionPackages", "com.***.action");
webApp.addServlet(XFireServlet.class, "/*");
webApp.addEventListener(new ServletContextListener() {
public void contextInitialized(ServletContextEvent sce) {
//use spring context to build a webApplicationContext
context = new WebApplicationContextWrapper(originalContext, sce.getServletContext());
//make spring work with servlet Container
sce.getServletContext().setAttribute(
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context);
}
public void contextDestroyed(ServletContextEvent sce) {
}
});
server.addHandler(webApp);
server.start();
} catch (Exception e) {
...
}
分享到:
相关推荐
web.xml配置详解web.xml配置详解web.xml配置详解web.xml配置详解web.xml配置详解web.xml配置详解web.xml配置详解
全面详细讲述web.xml个元素的用途 还有实例哦
web.xml配置文件详解让开发人员更加清楚web.xml是怎么配置。以及各个配置的作用。
在web.xml中引入其他xml配置文件的步骤,含引入错误解决。
Tomcat中用web.xml控制Web应用详解
struts.xml和applicationContext.xml、web.xml的配置
SpringMVC基于代码的配置方式(零配置,无web.xml) 本资源博客地址:http://blog.csdn.net/u013816347/
web.xml 各属性作用描述 Web.xml 常用元素 <web‐app> ‐name>‐name>定义了WEB 应用的名字 <description></description> 声明WEB 应用的描述信息
spring在web.xml中和在struts中的不同配置..pdf
web.xml加载顺序与web.xml常用节点解析
servlet的写登陆管理系统用到的web.xml
spring-mvc.xml spring-mybatis.xml web.xml log4j.properties,项目中需要用到的配置文件。直接可用。
为tomcat服务器配置https,tomcat需要设置的server.xml与web.xml配置。可以帮助小白为tomcat服务器配置https协议(域名)。
jboss-web.xml jndi.properties oracle-ds.xml三个文件,EJB+JPA 所需要的一些配置文件
spring无web.xml零配置,使用javaconfig来进行spring配置,本项目使用maven管理,
application.xml配置文件详解 application.xml配置文件详解 application.xml配置文件详解
请在web.xml文件中使用– page >元素为整个web应用程序设置错误处理页面。已知:处理状态码为404的页面为404.jsp,处理状态码为500的页面为500.jsp。
web.xml dwr.xml 任何一个dwr.xml的文件都需要包含DWR DOCTYPE的声明行,。。 有几个术语有必要理解,参数叫做converted,远程Bean叫做created.如果远程Bean A有个方法A.blah(B),那么你需要为A建立一个created,为B建立...
web.xml 配置详解,需要的下载了。。。Web.xml常用元素和在java web规范中说明.按照listner,filter,servlet的顺序初始化
在web.xml中配置action或.do,附上详细的文档