spring开发指南.doc

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Spring初探 开始Spring研究之前,先让我们来看一个1分钟上手教程. Quick Start! 准备工作 下载SpringFramework的最新版本,并解压缩到指定目录. 在IDE中新建一个项目,并将Spring.jar将其相关类库加入项目. 笔者所用IDE为Eclipse,类库配置如下: Spring采用Apache common_logging,并结合Apache log4j作为日志输出组件.为了在 调试过程中能观察到Spring的日志输出,在CLASSPATH中新建perties配置文件, 内容如下: log4j.rootLogger=DEBUG, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%c{1} - %m%n 配置完成后,项目结构如下图所示: SpringFrameWork Developers Guide Version 0.6 October 8, 2004 So many open source projects. Why not Open your Documents 构建Spring基础代码 示例基础代码包括: 1. Action接口: Action接口定义了一个execute方法,在我们示例中,不同的Action实现提供了各自的 execute方法,以完成目标逻辑. public interface Action { public String execute(String str); } 2. Action接口的两个实现UpperAction,LowerAction public class UpperAction implements Action { private String message; public String getMessage() { return message; } public void setMessage(String string) { message = string; } public String execute(String str) { return (getMessage() + str).toUpperCase(); } } UpperAction将其message属性与输入字符串相连接,并返回其大写形式. public class LowerAction implements Action { private String message; SpringFrameWork Developers Guide Version 0.6 October 8, 2004 So many open source projects. Why not Open your Documents public String getMessage() { return message; } public void setMessage(String string) { message = string; } public String execute(String str) { return (getMessage()+str).toLowerCase(); } } LowerAction将其message属性与输入字符串相连接,并返回其小写形式. 3. Spring配置文件(bean.xml) Spring Quick Start HeLLo (请确保配置bean.xml位于工作路径之下,注意工作路径并不等同于CLASSPATH ,eclipse 的默认工作路径为项目根路径,也就是.project文件所在的目录,而默认输出目录/bin是项目 CLASSPATH的一部分,并非工作路径.) 4. 测试代码 public void testQuickStart() { ApplicationContext ctx=new FileSystemXmlApplicationContext(bean.xml); Action action = (Action) ctx.getBean(TheAction); System.out.println(action.execute(Rod Johnson)); } 可以看到,上面的测试代码中,我们根据bea

文档评论(0)

yan666888 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档