Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > Java > Spring in Action 笔记(I)
【标  题】:Spring in Action 笔记(I)
【关键字】:Spring,in,Action
【来  源】:http://www.blogjava.net/51AOP/archive/2006/05/22/47456.html

Spring in Action 笔记(I)

Your Ad Here

By : icess ,我的部落格 http://blog.matrix.org.cn/page/icess

在考试前匆匆看了一遍Spring in Action 也没有记录什么,考试结束了,要抓紧时间整理一下.要不然就忘了.^_^:

整理一下我目前可能会用到的模块, 对于那些现在根本用不到的冬冬还是等有时间再研究吧!

第一个当然是最经典的HelloWorld 了 , 呵呵,简单,但是说明了原理.

定义一个服务接口

package? test.helloworld;

public?interface? GreetingService?{
?? public?void? sayGreeting();

}

下面是其实现:

package? test.helloworld;

public?class? GreetingServiceImpl? implements? GreetingService?{

?? private? String?greeting;
?? public? GreetingServiceImpl()?{}
?? public? GreetingServiceImpl(String?greeting)?{
???? this .greeting?=?greeting;
?? }
?? public?void? sayGreeting()?{
???? //??Auto-generated?method?stub
???? System.out.println(greeting);
?? }
??
?? public?void? setGreeting(String?greeting)?{
???? this .greeting?=?greeting;
?? }

}

然后就是测试 IoC 的测试代码:

package? test.helloworld;


import? org.springframework.beans.factory.BeanFactory;
import? org.springframework.beans.factory.xml.XmlBeanFactory;
import? org.springframework.context.ApplicationContext;
import? org.springframework.context.support.ClassPathXmlApplicationContext;
import? org.springframework.core.io.FileSystemResource;

public?class? HelloApp?{

?? /**
??? *? @param? args
??? */
?? public?static?void? main(String[]?args)?{
???? //?TODO?Auto-generated?method?stub
//????BeanFactory?factory;
//????factory?=?new?XmlBeanFactory(new?FileSystemResource("src/test/helloworld/hello.xml"));
???? //?使用不同的方法得到bean.?(BeanFactory?or?ApplicationContext)
???? ApplicationContext?context?=? new? ClassPathXmlApplicationContext( "test/helloworld/hello.xml" );
????
????
???? GreetingService?greetingService?=?(GreetingService)?context.getBean( "greetingService" );
//????GreetingService?greetingService?=?(GreetingService)?factory.getBean("greetingService");
???? greetingService.sayGreeting();
?? }

}

还有重要的配置文件如下:hello.xml

<?

xml version = "1.0" encoding = "UTF-8" ?>

<!

DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"

"http://www.springframework.org/dtd/spring-beans.dtd" >

<

beans >

< bean id = "greetingService"

class = "test.helloworld.GreetingServiceImpl" >

< property name = "greeting" >

< value > ice rain ! </ value >

</ property >

</ bean >

</

beans >

呵呵就这么简单,实现了 greeting 属性的 Ioc.

这是Spring 两大基本支柱其一的工作原理, 关于AoP的内容,在这里不作讨论,因为现在我使用AoP的地方不是很多,简单的应用是很简单的啦.^_^.

下面一篇我们来看看 在spring包装下的jdbc访问. 详细情况也可以参考这里

openfans领域模型驱动的尝试:【上一篇】
菜鸟求解 (编程实现360阶扰动重力 ):【下一篇】
【相关文章】
  • windows 系统的hosts文件
  • FreeMarker Eclipse Plugin的安装!
  • Java程序的性能优化StringBuffer与Vector
  • spring的精髓在于注入bean
  • Lucene In Action
  • _kbhit() for Linux
  • 日记 [2006年05月22日]Linux Oracle 安装
  • fortinet ipsec vpn设置一点心得!
  • Solaris上对比测试BIND和Nominum两个DNS软件性能
  • Caching
  • 【随机文章】
  • 窗口类的诞生(注册自己的窗口类一)
  • vs.net2005beta2 与 vs.net2003的区别
  • 将日志文件根据业务类型分级别输出的不同的文件中
  • 启用FreeBSD 5-CURRENT的ULE调度器
  • Director Lingo 语言入门(10)
  • WebSphere快速入门(8)
  • .net与SAP Portal登陆SSO方法
  • 如何检测备注字段的字节数
  • 理解Linux配置文件简介
  • 使用索引服务器 - 使用索引服务器的对象
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.