惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Privacy & Cybersecurity Law Blog
V
V2EX
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Register - Security
The Register - Security
MongoDB | Blog
MongoDB | Blog
P
Privacy International News Feed
The Last Watchdog
The Last Watchdog
Security Archives - TechRepublic
Security Archives - TechRepublic
美团技术团队
Stack Overflow Blog
Stack Overflow Blog
博客园 - 司徒正美
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
K
Kaspersky official blog
S
Secure Thoughts
T
Tenable Blog
Security Latest
Security Latest
The Cloudflare Blog
S
Security @ Cisco Blogs
H
Heimdal Security Blog
aimingoo的专栏
aimingoo的专栏
TaoSecurity Blog
TaoSecurity Blog
Blog — PlanetScale
Blog — PlanetScale
Microsoft Security Blog
Microsoft Security Blog
Schneier on Security
Schneier on Security
Webroot Blog
Webroot Blog
G
Google Developers Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Scott Helme
Scott Helme
IT之家
IT之家
Latest news
Latest news
The Hacker News
The Hacker News
C
Check Point Blog
T
The Exploit Database - CXSecurity.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
腾讯CDC
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
N
News | PayPal Newsroom
Forbes - Security
Forbes - Security
P
Palo Alto Networks Blog
S
Security Affairs
S
Securelist
Google Online Security Blog
Google Online Security Blog
WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
C
Cybersecurity and Infrastructure Security Agency CISA
A
About on SuperTechFans

博客园 - 飘扬的笨蛋

忘记了这个地方 想起了父亲 singleton 很就没来了 oracle 10G在fedora2上的安装 vi 使用 spring and webwork (ref from webwork wiki) oracle 想起了以前 无题 avalon 无题 - 一次建模 Avalon简介 重回Avalon JMS 学习 jpetstore学习第4章 jpetstore学习第3章 OrderService.java jpetstore学习第2章 关于PetStoreFacade.java 开始学习springframework带的jpetsore
picocontainer & ioc 最简单的例子
飘扬的笨蛋 · 2004-08-13 · via 博客园 - 飘扬的笨蛋

Boy.java
/*
 * Created on 2004-8-14
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.pp;

/**
 * @author pp
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public interface Kissable {
    public void kiss();
}
Kissable.java
package com.pp;

/**
 * @author pp
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Boy implements Kissable{
    public void kiss(){
        System.out.println("KISS");
    }
}
Girl.java
package com.pp;

import org.picocontainer.Startable;

/**
 * @author pp
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Girl implements Startable{
    Kissable kissable ;
    public Girl(Kissable kissable){
        this.kissable = kissable;
    }
   
    public void start(){
        kissable.kiss();
    }
   
    public void stop(){}
}

Main.java
package com.pp;

import org.picocontainer.MutablePicoContainer;
import org.picocontainer.defaults.DefaultPicoContainer;

/**
 * @author pp
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Main {

    public static void main(String[] args) {
        MutablePicoContainer pico = new DefaultPicoContainer();
        pico.registerComponentImplementation(Boy.class);
        pico.registerComponentImplementation(Girl.class);
        pico.start();
        Girl girl = (Girl)pico.getComponentInstance(Girl.class);
        //girl.kissone();
        pico.stop();
        pico.dispose();
    }    
       
}

如果不用pico来管理,则Main函数看起来是这样的  
   public static void main(String[] args){
        Kissable kissable = new Boy();
        Girl girl = new Girl(kissable);
        girl.start();
    }
也就是说你必须自己来维护Boy对象,

如果在Spring则看起来是这样的
<beans>
     <bean id=“boy“ class=“com.pp.Boy“/>
     <bean id=“girl“ class=“com.pp.Girl“>
             <properties name=“kissable“><ref bean=“boy“/></properties>
     </bean>
</beans>