Chinaunix首页 | 论坛 | 博客
  • 博客访问: 30392157
  • 博文数量: 708
  • 博客积分: 12163
  • 博客等级: 上将
  • 技术积分: 8240
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-04 20:59
文章分类

全部博文(708)

分类: Java

2008-11-26 15:14:05

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拦截器


阅读(1982) | 评论(0) | 转发(0) |
0

上一篇:使用JSON

下一篇:seasar组件自动注册

给主人留下些什么吧!~~