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

    <?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"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
        <bean id="test" class="org.crazyit.app.service.TestBean"/>
    </beans>
    <?xml version="1.0" encoding="GBK"?>
    <计算机书籍列表>
        <书>
            <书名>疯狂Java讲义</书名>
            <作者>李刚</作者>
        </书>
        <书>
            <书名>轻量级Java EE企业应用实战</书名>
            <作者>李刚</作者>
        </书>
    </计算机书籍列表>
    package lee;
    
    import org.springframework.context.*;
    import org.springframework.context.support.*;
    import org.springframework.core.io.*;
    
    import org.dom4j.io.XPPReader;
    import org.dom4j.Document;
    import org.dom4j.Element;
    
    import java.util.*;
    
    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容器
            ApplicationContext ctx = new
                ClassPathXmlApplicationContext("beans.xml");
            // 获取容器中名为test的Bean实例
            TestBean tb = ctx.getBean("test" , TestBean.class);
            // 通过tb实例来获取ResourceLoader对象
            ResourceLoader rl = tb.getResourceLoader();
            // 判断程序获得ResourceLoader和容器是否相同
            System.out.println(rl == ctx);
        }
    }
    package org.crazyit.app.service;
    
    import org.springframework.context.ResourceLoaderAware;
    import org.springframework.core.io.ResourceLoader;
    
    /**
     * 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 TestBean implements ResourceLoaderAware
    {
        private ResourceLoader rd;
        // 实现ResourceLoaderAware接口必须实现的方法
        // 如果把该Bean部署在Spring容器中,该方法将会由Spring容器负责调用
        // Spring容器调用该方法时,Spring会将自身作为参数传给该方法
        public void setResourceLoader(ResourceLoader resourceLoader)
        {
            this.rd = resourceLoader;
        }
        // 返回ResourceLoader对象的引用
        public ResourceLoader getResourceLoader()
        {
            return rd;
        }
    }
  • 相关阅读:
    md基本语法
    CodeBlocks安装使用、汉化以及更改配色
    hexo+github搭建个人博客教程和各种坑记录
    GB/T 38637.1-2020 物联网 感知控制设备接入 第1部分:总体要求
    山东大学909数据结构与程序设计考研经验分享
    GB/T 39083-2020 快递服务支付信息交换规范
    GB/T 38829-2020 IPTV媒体交付系统技术要求 内容接入
    GB/T 37733.3-2020 传感器网络 个人健康状态远程监测 第3部分:终端技术要求
    GB/T 38801-2020 内容分发网络技术要求 互联应用场景
    GB/T 30269.809-2020 信息技术 传感器网络 第809部分:测试:基于IP的无线传感器网络网络层协议一致性测试
  • 原文地址:https://www.cnblogs.com/tszr/p/12372271.html
Copyright © 2011-2022 走看看