简单介绍一下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. iOS App上线的秘密

    App上线需要准备几个证书:首先是是CSR证书,要创建这个证书需要在自己电脑上找到钥匙串访问(在应用程序->其他 里面).钥匙串访问->证书助理->从证书颁发机构请求证书如下: 创建 ...

  2. [Architecture Design] 累进式Domain Layer

    [Architecture Design] 累进式Domain Layer 前言 本篇的内容大幅度的简化了分析设计.面向对象等等相关知识,用以传达累进式Domain Layer的核心概念.实际开发软件 ...

  3. JavaScript的作用域和闭包

    首发于:https://mingjiezhang.github.io/ 闭包和作用域有着千丝万缕的联系. js的作用域 具体的作用域我就不展开叙述了.其中很重要的两点就是:js的作用域链机制和函数词法 ...

  4. LinearLayout嵌套

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  5. thinkPHP学习笔记(1)

    现在对前端的要求越来越高了  基本上身为一个前端人员需要会一种后台语言,于是选择了当下流行的php.因为是自学对我这个不怎么懂代码的人来说还是有点难度的. 1.先看看thinkphp的目录结构 ├─T ...

  6. 如何通过PowerShell在Visual Studio的Post-build中预热SharePoint站点

    问题现象 Visual Studio在开发SharePoint的时候,发布部署包后,首次打开及调试站点页面的时候会非常的慢 解决方案 使用PowerShell脚本,加载SharePoint插件后遍历所 ...

  7. SPJS Upload for SharePoint: Custom upload page for uploading documents to various document libraries in a site collection

    http://spjsblog.com/2013/12/08/spjs-upload-for-sharepoint-custom-upload-page-for-uploading-documents ...

  8. Hibernate学习0.Hibernate入门

    Hibernate是什么 面向java环境的对象/关系数据库映射工具. 1.开源的持久层框架. 2.ORM(Object/Relational Mapping)映射工具,建立面向对象的域模型和关系数据 ...

  9. ReactiveCocoa中信号的使用

    前言: 很早之前就有看过ReactiveCocoa,那会看的时候知道是一个新的框架关于响应式编程,具体什么也没有深入研究,今天也对ReactiveCocoa这个框架的使用进行了一定的了解.在githu ...

  10. WPF x名称空间

    X是映射XML名称空间时给他取的名字.X名称空间里面的成员是专门给XAML编译器看的.用来引导XAML编译器把XAML代码编译成CLR代码的,他是取的XAML的首字母X. XAML有自己的编译器,会吧 ...