JETTY嵌入式Web容器的开发(三)—集成struts2,spring。
JETTY嵌入式开发步骤
下载
同
jetty-hightide-8.1.4.v20120524.zip
本文采用struts2.1.8和spring 2.5.6
ECLIPSE建立一个普通JAVA项目testjetty
建项目步骤同
建成的项目的结构如下:
修改/jetty/etc/jetty.xml
同
JETTY Service类
Service类同
做一个简单的可执行的服务启动类
package org.jetty.demo;
public class JettyServerStart {
public static void main(String[] args) {
JettyCustomServer server = new JettyCustomServer(“./jetty/etc/jetty.xml”,”/testContext”);
server.startServer();
}
}
集成入struts和spring
将struts2.1.8和spring 2.5.6的jar包拷贝入项目的buildpath
Src目录下建立struts.properties和struts.xml\
Src下建立目录/spring,里面建立applicationContext.xml
项目架构:
加入struts,spring的测试逻辑
/spring/applicationContext.xml
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:aop=”http://www.springframework.org/schema/aop” xmlns:tx=”http://www.springframework.org/schema/tx” xmlns:context=”http://www.springframework.org/schema/context” xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd” default-autowire=”byName” default-lazy-init=”false”>
struts.xml
“-//Apache Software Foundation//DTD Struts Configuration 2.0//EN”
“http://struts.apache.org/dtds/struts-2.0.dtd”>
cn/com/test/action/struts-admin-action.xml
“-//Apache Software Foundation//DTD Struts Configuration 2.0//EN”
“http://struts.apache.org/dtds/struts-2.0.dtd”>
package cn.com.test.action;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.opensymphony.xwork2.ActionSupport;
@Controller(“testAction”)
@Scope(“prototype”)
public class TestAction extends ActionSupport {
private static final long serialVersionUID = 9026533527322851032L;
private static Log logger = LogFactory.getLog(TestAction.class);
public String execute() {
ServletActionContext.getRequest().setAttribute(“message”, “struts,spring测试”);
return SUCCESS;
}
}
/webRoot/jsp/success.jsp
<%@ page language="java" contentType="text/html; charset=GBK"
pageEncoding=”GBK”%>
success!!! ${message}
启动服务
执行JettyServerStart
2012-06-27 17:14:10.859:INFO:oejs.Server:jetty-8.1.4.v20120524
2012-06-27 17:14:11.250:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/testContext,file:/D:/RND/javaathome/eclipsehelio/testjetty/webRoot/}
2012-06-27 17:14:11.250:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/testContext,file:/D:/RND/javaathome/eclipsehelio/testjetty/webRoot/}
2012-06-27 17:14:11.375:INFO:/testContext:Initializing Spring root WebApplicationContext
2012-06-27 17:14:11,375 INFO ContextLoader.initWebApplicationContext(189)-Root WebApplicationContext: initialization started
2012-06-27 17:14:11,406 INFO XmlWebApplicationContext.prepareRefresh(411)-Refreshing org.springframework.web.context.support.XmlWebApplicationContext@39ab89: display name [Root WebApplicationContext]; startup date [Wed Jun 27 17:14:11 CST 2012]; root of context hierarchy
2012-06-27 17:14:11,484 INFO XmlBeanDefinitionReader.loadBeanDefinitions(323)-Loading XML bean definitions from file [D:\RND\javaathome\eclipsehelio\testjetty\bin\spring\applicationContext.xml]
2012-06-27 17:14:11,734 INFO XmlWebApplicationContext.obtainFreshBeanFactory(426)-Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@39ab89]: org.springframework.beans.factory.support.DefaultListableBeanFactory@419d05
2012-06-27 17:14:11,843 INFO DefaultListableBeanFactory.preInstantiateSingletons(414)-Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@419d05: defining beans [org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,testAction]; root of factory hierarchy
2012-06-27 17:14:11,843 INFO ContextLoader.initWebApplicationContext(209)-Root WebApplicationContext: initialization completed in 468 ms
2012-06-27 17:14:11.843:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/testContext,file:/D:/RND/javaathome/eclipsehelio/testjetty/webRoot/}
2012-06-27 17:14:11.843:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/testContext,file:/D:/RND/javaathome/eclipsehelio/testjetty/webRoot/}
2012-06-27 17:14:12,031 INFO XmlConfigurationProvider.info(31)-Parsing configuration file [struts-default.xml]
2012-06-27 17:14:12,187 INFO XmlConfigurationProvider.info(31)-Parsing configuration file [struts-plugin.xml]
2012-06-27 17:14:12,203 INFO XmlConfigurationProvider.info(31)-Parsing configuration file [struts.xml]
2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (spring) for class com.opensymphony.xwork2.ObjectFactory
2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for class com.opensymphony.xwork2.conversion.impl.XWorkConverter
2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for interface com.opensymphony.xwork2.TextProvider
2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for interface com.opensymphony.xwork2.ActionProxyFactory
2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for interface com.opensymphony.xwork2.conversion.ObjectTypeDeterminer
2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for interface org.apache.struts2.dispatcher.mapper.ActionMapper
2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (jakarta) for interface org.apache.struts2.dispatcher.multipart.MultiPartRequest
2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for class org.apache.struts2.views.freemarker.FreemarkerManager
2012-06-27 17:14:12,218DEBUG BeanSelectionProvider.debug(57)-Choosing bean (struts) for class org.apache.struts2.views.velocity.VelocityManager to be loaded from the ObjectFactory
2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for interface org.apache.struts2.components.UrlRenderer
2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for interface com.opensymphony.xwork2.validator.ActionValidatorManager
2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for interface com.opensymphony.xwork2.util.ValueStackFactory
2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for interface com.opensymphony.xwork2.util.reflection.ReflectionProvider
2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for interface com.opensymphony.xwork2.util.reflection.ReflectionContextFactory
2012-06-27 17:14:12,234 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for interface com.opensymphony.xwork2.util.PatternMatcher
2012-06-27 17:14:12,234 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for interface org.apache.struts2.dispatcher.StaticContentLoader
2012-06-27 17:14:12,234 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for interface com.opensymphony.xwork2.UnknownHandlerManager
2012-06-27 17:14:12,234 INFO BeanSelectionProvider.info(31)-Loading global messages from com.demo.struts2.resources.ApplicationResources
2012-06-27 17:14:12,359 INFO StrutsSpringObjectFactory.info(31)-Initializing Struts-Spring integration…
2012-06-27 17:14:12,375 INFO SpringObjectFactory.info(31)-Setting autowire strategy to name
2012-06-27 17:14:12,375 INFO StrutsSpringObjectFactory.info(31)-… initialized Struts-Spring integration successfully
2012-06-27 17:14:13.265:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:8088
current thread:30| idle thread:26
测试
测试访问http://localhost:8088/testContext/test/test.do
分享: 0
喜欢
0
赠金笔
阅读(1156)┊ 评论 (1)┊ 收藏(0) ┊转载(0) ┊ 喜欢▼ ┊打印┊举报 已投稿到: 排行榜
转载列表:
转载
转载是分享博文的一种常用方式…
前一篇:JETTY嵌入式Web容器的开发(二)—部署外部WAR包后一篇:分布式EHCACHE系统在缓存同步上存在着不小的缺陷
评论 重要提示:警惕虚假中奖信息 [发评论]新浪网友
非常感谢,2012-12-12 10:41举报删除分享回复(0)
发评论
登录名: 密码: 找回密码 注册 记住登录状态
昵 称:
分享到微博 评论并转载此博文
验证码: 请点击后输入验证码 收听验证码
匿名评论发评论
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。
< 前一篇
JETTY嵌入式Web容器的开发(二)—部署外部WAR包后一篇 >
分布式EHCACHE系统在缓存同步上存在着不小的缺陷
新浪BLOG意见反馈留言板 不良信息反馈 电话:4006900000 提示音后按1键(按当地市话标准计费) 欢迎批评指正
新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 会员注册 | 产品答疑
Copyright © 1996 – 2014 SINA Corporation, All Rights Reserved
新浪公司 版权所有
X选择其他平台 >>分享到
含“”的博文含“”的博主含“”的音乐含“”的视频最近喜欢了的博主:
加载中…Qing博客转载原文采编长微博神回复神回复,只要1积分就可以了哦
发表取消
发表成功 赠金笔关闭
金笔兑换今日土豪榜今日提名榜
兑换服务:金笔道具赠送数量:1支10支20支50支100支
其他现有金笔:0支还需兑换:1支 x 10=10(积分)确认点击了解更多规则
为了您的账号安全,请绑定邮箱
分
http://blog.sina.com.cn/s/blog_6151984a0101505f.html