Wu Yuxiong - natural born flyweight JAVA EE enterprise application development Struts2Sping4Hibernate Integrated Development Study Notes: Spring_myspring

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/common-logging"/>
    <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Sprin4.0.4"/>
    <classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>myspring</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
</projectDescription>
<? xml Version = "1.0" encoding = "GBK"?> 
<Beans xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" 
    xmlns = "http://www.springframework.org / Schema / Beans " 
    xsi: schemaLocation =" http://www.springframework.org/schema/beans 
    HTTP: // www.springframework.org/schema/beans/spring-beans-4.0.xsd "> 
    <-! Bean person named configuration which implementing class is a class org.crazyit.app.service.Person -> 
    <the bean ID = "person" class = "org.crazyit.app.service.Person"> 
        <-! control call setAxe () method of the container as a parameter passed axe Bean -> 
        <Property name = "Ax" REF = "Ax" /> 
    </ the bean> 
    <!- Configuration Bean called Ax, the implementing class is a class org.crazyit.app.service.Axe -> 
    <the bean ID = "Ax" class= "org.crazyit.app.service.Axe" /> 
    <-! arranged Bean called win, which implementing class is a class javax.swing.JFrame -> 
    <the bean ID = "win" class = "the javax. swing.JFrame "/> 
    <-! Bean configuration called date, which is the implementation class java.util.Date class -> 
    <the bean ID =" date " class =" java.util.Date "/> 
</ beans>
package lee;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import org.crazyit.app.service.*;
/**
 * Description:
 * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
 * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
 * <br/>This program is protected by copyright laws.
 * <br/>Program Name:
 * <br/>Date:
 * @author  Yeeku.H.Lee [email protected]
 * @version  1.0
 
{BeanTestclasspublic* /
 
    public  static  void main (String [] args) throws Exception 
    { 
        // create Spring container 
        the ApplicationContext CTX = new new 
            the ClassPathXmlApplicationContext ( "the beans.xml" );
         // Get the person id is Bean 
        the Person ctx.getBean P = ( "person", . the Person class );
         // call useAxe () method 
        p.useAxe (); 
    } 
}
package org.crazyit.app.service;

/**
 * Description:
 * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
 * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
 * <br/>This program is protected by copyright laws.
 * <br/>Program Name:
 * <br/>Date:
 * @author  Yeeku.H.Lee [email protected]
 * @version  1.0
 */
public class Axe
{
    public String chop()
    {
        return "使用斧头砍柴";
    }
}
package org.crazyit.app.service;

/**
 * Description:
 * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
 * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
 * <br/>This program is protected by copyright laws.
 * <br/>Program Name:
 * <br/>Date:
 * @author  Yeeku.H.Lee [email protected]
 * @version  1.0
 */
public class Person
{
    private Axe axe;
    // 设值注入所需的setter方法
    public void setAxe(Axe axe)
    {
        this.axe = axe;
    }
    public  void useAxe () 
    { 
        System.out.println ( "I'm going to chop firewood point!" );
         // call axe the chop () method,
         // show axe Person object depends on the object 
        System.out.println (axe. CHOP ()); 
    } 
}

 

Guess you like

Origin www.cnblogs.com/tszr/p/12370284.html