免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1322 | 回复: 0
打印 上一主题 下一主题

seasar的helloworld以及三种注入方式 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-11-26 15:14 |只看该作者 |倒序浏览

1.IHelloWorld接口
package org.tie.seasar1.service;
public interface IHelloWorld {
public void sayHello();
public void constructDI();
public void seterDI();
public void methodDI();
}
2.IHelloWorld接口的实现
package org.tie.seasar1.service.impl;
import org.tie.seasar1.service.IHelloWorld;
public class HelloWorld implements IHelloWorld {
private String msg1;
private String msg2;
private String msg3;
public String getMsg2() {
    return msg2;
}
public void setMsg2(String msg2) {
    this.msg2 = msg2;
}
public HelloWorld(String msg1) {
    super();
    this.msg1 = msg1;
}
public void sayHello() {
    System.out.println("hello world");
}
public void constructDI() {
    System.out.println(msg1);
}
public void seterDI() {
    System.out.println(msg2);
}
public void init(String msg3) {
    this.msg3 = msg3;
}
public void methodDI(){
    System.out.println(msg3);
}
}
3.客户端测试类
package org.tie.seasar1.client;
import org.apache.log4j.Logger;
import org.seasar.framework.container.S2Container;
import org.seasar.framework.container.factory.S2ContainerFactory;
import org.tie.seasar1.service.impl.HelloWorld;
public class HelloWorldClient {
private static final Logger log = Logger.getLogger(HelloWorldClient.class);
private static final String PATH = "dicon/helloworld.dicon";
public static void main(String[] args) {
S2Container container = S2ContainerFactory.create(PATH);
    container.init();
    HelloWorld helloWorld = (HelloWorld) container
      .getComponent("helloWorld");
    helloWorld.sayHello();
    helloWorld.constructDI();
    helloWorld.seterDI();
    helloWorld.methodDI();
    log.info("quick start");
}
}
4.DI配置文件:helloworld.dicon

    "构造函数注入"
    "设定函数注入"
   
              "方法函数注入"
         
  
    aop.traceInterceptor                                       
------------AOP拦截器



本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/55983/showart_1667383.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP