简单介绍一下spring,一方面带新手入入门,一方面自己也重温一下
第一个小工厂先暂时不用maven,下一个会用maven来来配置

jar包只需要一个,spring版本为2.5(暂时为2.5,后续更新,基本核心都是一样的),引入spring.jar到lib,如下:

在src下新建applicationContext.xml文件,结果如下:

内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <!-- 把一个类放入到spring容器中,该类就称为bean -->
<!-- 描述一个类 id 唯一标示 class 类名 -->
<bean id="helloWorld" class="com.lee.spring001.createobject.HelloWorld"></bean> </beans>

在com.lee.spring001.createobject包下新建类HelloWorld.java :

package com.lee.spring001.createobject;

public class HelloWorld {

    public HelloWorld() {
System.out.println("HelloWorld...");
} /**
*
*/
public void hello() {
System.out.println("Hello world!");
}
}

测试:

 package com.lee.spring001.createobject;

 import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class HelloWorldTest { @Test
public void testHelloWorld() { ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); HelloWorld hello = (HelloWorld)context.getBean("helloWorld");
hello.hello();
}
}

这样运行junit,成功

github地址:https://github.com/leechenxiang/maven-spring001-helloworld

Spring 一二事(1)的更多相关文章

  1. Spring 一二事(4) - 单例

    spring bean配置后再默认情况下是单例的,如果需要配置可以选择 prototype, request, session和global session 在配置spring mvc的action时 ...

  2. Spring 一二事(9) - xml 形式的 AOP

    AOP在spring中是非常重要的一个 在切面类中,有5种通知类型: aop:before  前置通知 aop:after-returning  后置通知 aop:after  最终通知 aop:af ...

  3. Spring 一二事(8) - annotation 形式的 MVC

    <!-- component:把一个类放入到spring容器中,该类就是一个component 在base-package指定的包及子包下扫描所有的类 --> <context:co ...

  4. Spring 一二事(7) - annotation

    之前的文章大多都是一带而过,一方面比较简单,一方面不是用的注解形式 在企业开发中,主要还是使用的注解来进行开发的 1 <!-- component:把一个类放入到spring容器中,该类就是一个 ...

  5. Spring 一二事(10) - annotation AOP

    先贴出POM的内容,这个毕竟是用的maven来简单构建的 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:x ...

  6. Spring 一二事(5) - 依赖注入

    <!-- 依赖注入的装配过程 --> <bean id="person" class="com.lee.spring007.di.xml.setter. ...

  7. Spring 一二事(3) - 别名

    别名就是可以通过另外一个名字来访问如下,已有bean:helloWorld3,那么定义别名(alias )后,就能使用“abc”来访问 <bean id="helloWorld3&qu ...

  8. Spring 一二事(2)

    静态工厂方法及实例工厂的使用: applicationContext.xml: <!-- factory-method 是指调用静态工厂方法 --> <bean id="h ...

  9. Spring 一二事(6) - IOC MVC 简易搭建

    <bean id="personAction" class="com.lee.spring008.IOC.DI.MVC.PersonAction"> ...

随机推荐

  1. Web网站数据”实时”更新设计

    请注意这个实时打上了双引号,没有绝对的实时,只是时间的颗粒不一样罢了(1ms,1s,1m). 服务器数据有更新可以快速通知客户端.Web 基于取得模式,而服务器建立大量的和客户端连接来提供数据实时更新 ...

  2. Play Framework框架 JPA惯用注解

    Play Framework框架 JPA常用注解 1.@Entity(name=”EntityName”) 必须 ,name 为可选 , 对应数据库中一的个表 2.@Table(name=”" ...

  3. jQuery waterbubble 水球图

    在线实例 默认效果 显示文本 水球半径 文本颜色 边框宽度 设置字体 数据多少 是否显示波纹 水球颜色 是否显示动画 使用方法 <div class="wrap"> & ...

  4. ASP.NET页面间传值总结

    本文我们将讨论的是ASP.NET页面间数据传递的几种方法,对此希望能帮助大家正确的理解ASP.NET页面间数据传递的用处以及便利性. Web页面是无状态的,服务器对每一次请求都认为来自不同用户,因此, ...

  5. iOS自定义AlertView 与 ActionSheet 遮罩提示+弹出动画

    产品大人总是能够想到很多让人欣慰的点子,基本所有能提示的地方都要很多文案啊图片之类 由此封装了一个半透明黑色遮罩的alert类(假装有图.jpg) 代码略糙,just share (逃 下载链接

  6. 多线程在iOS开发中的应用

    多线程基本概念 01 进程 进程是指在系统中正在运行的一个应用程序.每个进程之间是独立的,每个进程均运行在其专用且受保护的内存空间内. 02 线程 2-1 基本概念 1个进程要想执行任务,必须得有线程 ...

  7. Swift基础之闭包

    内容纲要: 1.闭包基础 2.关于闭包循环引用 正文: 1.闭包 闭包是自包含的函数代码块,可以在代码中被传递和使用.Swift 中的闭包与 C 和 Objective-C 中的代码块(blocks) ...

  8. linux ssh更换默认的22端口

    1.修改配置文件:/etc/ssh/sshd_config 2.先将Port 22 前面的 # 号去掉,并另起一行.如定义SSH端口号为26611 ,则输入 3.修改完毕后,重启SSH服务,并退出当前 ...

  9. 万恶的hao123

    Windows 10没办法直接在系统菜单栏上修改快捷图标的参数 在确认系统里面没有流氓软件之后,只能手工到文件夹下去修改了 C:\Users\你的用户名\AppData\Roaming\Microso ...

  10. Effective Java 63 Include failure-capture information in detail message

    Principle To capture the failure, the detail message of an exception should contain the values of al ...