1.下载开发包

http://repo.springsource.org/libs-release-local/org/springframework/spring

2.创建WEB工程,引入jar包

四个底层所必须的jar包

  

两个日志包

  在spring-framework-3.0.2.RELEASE-dependencies/org.apache.commons/com.springsource.org.apache.commons.logging/1.1.1
    com.springsource.org.apache.commons.logging-1.1.1.jar

  还需要引入log4j的jar包 spring-framework-3.0.2.RELEASE-dependencies\org.apache.log4j\com.springsource.org.apache.log4j\1.2.15
    com.springsource.org.apache.log4j-1.2.15.jar    将log4j的配置文件log4j.properties放在src,目录下
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.err
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### direct messages to file mylog.log ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=c\:mylog.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### set log levels - for more verbose logging change 'info' to 'debug' ###

log4j.rootLogger=info, stdout

3.创建接口与实现类

public interface UserService {

    public void sayHello();
}
public class UserServiceImpl implements UserService{

    @Override
    public void sayHello() {
        // TODO Auto-generated method stub
        System.out.println("Hello Spring!!");
    }

}

4.编写配置文件

  在src目录下创建applicationContext.xml的配置文件,名称是可以任意的,但是一般都会使用默认名称!!

  引入spring的约束,需要先找到具体的约束头信息!!  spring-framework-3.2.0.RELEASE\docs\spring-framework-reference\html\xsd-config.html
    具体的约束如下:
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="userService" class="com.spring.hellospring.serviceImpl.UserServiceImpl"/>

</beans>

5.编写测试程序

public class demo1 {

    /**
     * 原来的创建对象方式
     */
    @Test
    public void m01(){

        UserService userService = new UserServiceImpl();

        userService.sayHello();

    }

    /**
     * 利用Spring框架来管理对象
     */
    @Test
    public void m02(){

        //加载配置文件
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");

        //从Spring获取对象
        UserService userService = (UserService) ac.getBean("userService");

        //调用方法
        userService.sayHello();

    }

}

1.Spring【IOC】XML方式的更多相关文章

  1. 【Spring】XML方式实现(无参构造 有参构造)和注解方式实现 IoC

    文章目录 Spring IoC的实现方式 XML方式实现 通过无参构造方法来创建 1.编写一个User实体类 2.编写我们的spring文件 3.测试类 UserTest.java 4.测试结果 通过 ...

  2. Spring源码 04 IOC XML方式

    参考源 https://www.bilibili.com/video/BV1tR4y1F75R?spm_id_from=333.337.search-card.all.click https://ww ...

  3. Spring IOC 注入方式详解 附代码

    引言 Spring框架作为优秀的开源框架之一,深受各大Java开发者的追捧,相信对于大家来说并不陌生,Spring之所以这么流行,少不了他的两大核心技术IOC和IOP.我们这里重点讲述Spring框架 ...

  4. Spring基于XML方式的使用

    一.IoC配置 IoC的配置是通过Spring的xml文件的bean标签进行的. 1.bean标签介绍 bean标签一般是在xml文件进行配置的,xml文件一般样式如下: <?xml versi ...

  5. Spring通过XML方式实现定时任务

    package com.wisezone.service; import java.text.SimpleDateFormat; import java.util.Date; import org.s ...

  6. Spring IOC 实现方式

    Spring 中的 org.springframework.beans 包和 org.springframework.context 包构成了 Spring 框架 IoC 容器的基础. BeanFac ...

  7. Spring基于XML方式加载Bean定义信息(又名:Spring IOC源码时序图)-图解

  8. Spring IOC 注入方式

    依赖注入通常有如下两种方式: ①设值注入:IOC容器使用属性的Setter方法来注入被依赖的实例. 设值注入是指IOC容器使用属性的Setter方法来注入被依赖的实例.这种注入方式简单.直观,因而在S ...

  9. spring IOC注解方式详解

    本文分为三个部分:概述.使用注解进行属性注入.使用注解进行Bean的自动定义. 一,概述 注释配置相对于 XML 配置具有很多的优势: 它可以充分利用 Java 的反射机制获取类结构信息,这些信息可以 ...

  10. spring ioc xml配置

    一个完整的spring xml配置:是把action,service,dao以及其它的资源性配置(如basedao)和公共性配置(如连接数据库)配置在resource.xml中,这样就有四个xml配置 ...

随机推荐

  1. Linux命令速查手册(第2版)学习

    第1章.需要了解的命令行相关事项 表1-1 如何在文件名字符中使用特殊字符 字符 建议 / 绝不使用.不能转义 \ 必须转义.避免使用 _ 绝不能作为文件或目录名的第一个字符 [] 必须转义.避免使用 ...

  2. C++ 俄罗斯方块

    #include <iostream> #include <string.h> #include <stdlib.h> #include <time.h> ...

  3. 阿里云代码管理平台 Teambition Codeup(行云)亮相,为企业代码安全护航

    2019杭州云栖大会企业协作与研发效能专场,企业协同平台Teambition负责人齐俊元正式发布阿里云自研的代码管理平台Teambition Codeup(行云),Codeup是一款企业级代码管理产品 ...

  4. thinkphp 闭包支持

    闭包定义 我们可以使用闭包的方式定义一些特殊需求的路由,而不需要执行控制器的操作方法了,例如: 'URL_ROUTE_RULES'=>array( 'test' => function() ...

  5. 双线程DP

    1.传纸条 好像是一道普及组水题? //Twenty #include<cstdio> #include<iostream> #include<cstring> # ...

  6. 同一个tomcat 两个项目 互相访问接口方法

    package com.qif.xdqdm.util; import com.alibaba.fastjson.JSONObject; import java.io.*; import java.ne ...

  7. swoole手册

    https://wiki.swoole.com/wiki/ Swoole Github项目地址:https://github.com/swoole/swoole-src/ (支持请点Star) 开源中 ...

  8. MAMP mysql无法启动 总结(以后有发现再添加)

    1.错误信息Can't start server : Bind on unix socket: Address already in use 解析:主要原因是上次关闭Mysql是出现异常而导致的, 解 ...

  9. System.DateTime.cs

    ylbtech-System.DateTime.cs 1. 程序集 mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c5 ...

  10. Spring的refresh()方法相关异常

    如果是经常使用Spring,特别有自己新建ApplicationContext对象的经历的人,肯定见过这么几条异常消息:1.LifecycleProcessor not initialized - c ...