zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然轻量级JAVA EE企业应用开发Struts2Sping4Hibernate整合开发学习笔记:Spring_FieldRetrievingFactoryBean

    <?xml version="1.0" encoding="GBK"?>
    <project name="spring" basedir="." default="">
        <property name="src" value="src"/>
        <property name="dest" value="classes"/>
    
        <path id="classpath">
            <fileset dir="../../lib">
                <include name="**/*.jar"/>
            </fileset>
            <pathelement path="${dest}"/>
        </path>
    
        <target name="compile" description="Compile all source code">
            <delete dir="${dest}"/>
            <mkdir dir="${dest}"/>
            <copy todir="${dest}">
                <fileset dir="${src}">
                    <exclude name="**/*.java"/>
                </fileset>        
            </copy>
            <javac destdir="${dest}" debug="true" includeantruntime="yes"
                deprecation="false" optimize="false" failonerror="true">
                <src path="${src}"/>
                <classpath refid="classpath"/>
                <compilerarg value="-Xlint:deprecation"/>
            </javac>
        </target>
    
        <target name="run" description="Run the main class" depends="compile">
            <java classname="lee.SpringTest" fork="yes" failonerror="true">
                <classpath refid="classpath"/>
            </java>
        </target>
    
    </project>
    <?xml version="1.0" encoding="GBK"?>
    <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://www.springframework.org/schema/beans"
        xmlns:util="http://www.springframework.org/schema/util"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/util
        http://www.springframework.org/schema/util/spring-util-4.0.xsd">
    
        <!-- 将指定类的静态Field值定义成容器中的Bean实例-->
        <bean id="theAge1" class=
            "org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
            <!-- targetClass指定访问哪个目标类 -->
            <property name="targetClass" value="java.sql.Connection"/>
            <!-- targetField指定要访问的Field名 -->
            <property name="targetField" value="TRANSACTION_SERIALIZABLE"/>
        </bean>
    
        <!-- 简化配置
        <util:constant id="theAge1" 
        static-field="java.sql.Connection.TRANSACTION_SERIALIZABLE"/> -->
    
        <!-- 将指定类的静态Field值定义成容器中的Bean实例 -->
        <bean id="theAge2" class=
            "org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
            <!-- staticField指定访问哪个类的哪个静态Field -->
            <property name="staticField" 
                value="java.sql.Connection.TRANSACTION_SERIALIZABLE"/>
        </bean>
    
        <bean id="son" class="org.crazyit.app.service.Son">
            <property name="age">
                <!-- 指定java.sql.Connection.TRANSACTION_SERIALIZABLE
                    作为调用setAge()方法的参数值 -->
                <bean id="java.sql.Connection.TRANSACTION_SERIALIZABLE" class=
                "org.springframework.beans.factory.config.FieldRetrievingFactoryBean"/>
            </property>
        </bean>
    
        <!-- 简化配置
        <bean id="son" class="org.crazyit.app.service.Son">
            <property name="age">
                <util:constant
                static-field="java.sql.Connection.TRANSACTION_SERIALIZABLE"/>
            </property>
        </bean> -->
    </beans>
    package lee;
    
    import org.springframework.context.*;
    import org.springframework.context.support.*;
    
    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 kongyeeku@163.com
     * @version  1.0
     */
    public class SpringTest
    {
        public static void main(String[] args)
        {
            ApplicationContext ctx = new
                ClassPathXmlApplicationContext("beans.xml");
            System.out.println("系统获取theAge1的值:"
                + ctx.getBean("theAge1"));
            System.out.println("系统获取theAge2的值:"
                + ctx.getBean("theAge2"));
            System.out.println("系统获取son为:"
                + ctx.getBean("son"));
        }
    }
    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 kongyeeku@163.com
     * @version  1.0
     */
    public class Person
    {
        private int age;
        private Son son;
    
        //age属性的setter和getter方法
        public void setAge(int age)
        {
            this.age = age;
        }
        public int getAge()
        {
            return this.age;
        }
    
        //son属性的setter和getter方法
        public void setSon(Son son)
        {
            this.son = son;
        }
        public Son getSon()
        {
            return this.son;
        }
    }
    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 kongyeeku@163.com
     * @version  1.0
     */
    public class Son
    {
        private int age;
    
        // age的setter方法
        public void setAge(int age)
        {
            this.age = age;
        }
    
        public String toString()
        {
            return "Son[age= " + age + "]";
        }
    }
  • 相关阅读:
    <O(n),O(1)>的LCA
    hdu6110
    ACM模板
    prufer编码
    UvaLive6893_The_Big_Painting
    HDU5669
    Codeforces786B
    二分图部分总结
    Git简介和Windows下安装步骤
    笔记本电脑插入耳机后无法使用解决办法
  • 原文地址:https://www.cnblogs.com/tszr/p/12371917.html
Copyright © 2011-2022 走看看