1、导包

2、编写Helloworld程序

 package cn.test.helloWorld;

 public class HelloWorld {
public void sayHello(){
System.err.println("1234567890");
}
}

3、在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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!--
beans
把一个类放入到spring容器中,该类就称为bean
-->
<!--
一个bean就代表一个类
id就是唯一标识符[推荐命令规则是类的第一个字母小写]
-->
<bean name="helloWorld" class="cn.test.helloWorld.HelloWorld"></bean> </beans>

 这里也可以使用别名来配置,在bean下面添加:<alias name="helloWorld" alias="bm"/>,在后面的调用中就可以使用别名来调用了。

4、编写启动客户端

 @Test
public void doSomething(){
/*
* 1、启动spring容器
* 2、从spring容器中把helloWorld拿出来
* 3、对象.方法
*/
ApplicationContext applicationContext=new ClassPathXmlApplicationContext("/applicationContext.xml");
HelloWorld helloWorld=(HelloWorld) applicationContext.getBean("helloWorld");
helloWorld.sayHello();
}

使用别名调用:效果相同

ApplicationContext applicationContext=new ClassPathXmlApplicationContext("/applicationContext.xml");
HelloWorld helloWorld=(HelloWorld) applicationContext.getBean("bm");
helloWorld.sayHello();

Spring 环境搭建的更多相关文章

  1. Spring环境搭建之:导入jar包、配置文件名称及放置位置

    Spring环境搭建之:导入jar包.配置文件名称及放置位置 现在项目开发中spring框架应用的还是比较多的,自己用的还不太熟练,每次用的时候总配置半天,总有些配置弄错,就找个时间总结以下,方便以后 ...

  2. 【Spring学习笔记-1】Myeclipse下Spring环境搭建

    *.hl_mark_KMSmartTagPinkImg{background-color:#ffaaff;}*.hl_mark_KMSmartTagBlueImg{background-color:# ...

  3. 【Spring环境搭建】在Myeclipse下搭建Spring环境-web开发

    <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" ...

  4. Spring之Spring环境搭建

    Spring之Spring环境搭建 一.什么是Spring? Spring框架是由于软件开发的复杂性而创建的.Spring使用的是基本的JavaBean来完成以前只可能由EJB完成的事情.然而,Spr ...

  5. SSH环境搭建之Spring环境搭建篇

    SSH环境搭建之Spring环境搭建篇 一.引入Spring所使用的JAR文件 二.在src目录下创建beans.xml(Spring的容器文件) <?xml version="1.0 ...

  6. Spring环境搭建及简单demo

    1. Spring框架简介(以下这段话可用于面试求职) Spring为JavaEE开发提供了一个轻量级的解决方案,主要表现为, IOC(或者叫做DI)的核心机制,提供了bean工厂(Spring容器) ...

  7. eclipse Spring环境搭建 spring tool suite

    1.期初用intellij社区版,发现收费版才能开发Java EE. 2.使用eclipse按照网上的教程,在help->eclipse marketplace中搜索sts安装spring工具套 ...

  8. 01、Spring环境搭建

    环境:SpringSource-Tool-3.9.9.Eclipse4.10.0 首先,我们需要解决的是Spring包的问题,我看了百度.CSDN很多都是直接一上来随便丢个包就可以安装了,搞得我弄了一 ...

  9. 一、spring 环境搭建

    一.springtoolSuite4下载 1.概述 Spring Tools 4 是适用于您最喜欢的编码环境的下一代 Spring 工具.它主要从头开始重建,为开发基于 Spring 的企业应用程序提 ...

  10. spring环境搭建需要的插件-------Spring Tool Suite™ Downloads

    下载地址http://spring.io/tools/sts/all 上面的是集成了eclipse的,所以文件比较大,下面的是单独的插件,下载之后打开eclipse,help->installN ...

随机推荐

  1. Delphi编程中资源文件的应用

    Delphi编程中资源文件的应用/转自 http://chamlly.spaces.live.com/blog/cns!548f73d8734d3acb!236.entry一.引子: 现在的Windo ...

  2. div大小如何改变设置

    如果改变更改div大小尺寸. 首先我们要知道DIV大小是由高和宽确定,要修改DIV容积大小我们设置css宽度和css高度即可实现改变DIV盒子大小. 一.改变div大小实例 为了实验便于观察DIV盒子 ...

  3. Eight(bfs+全排列的哈希函数)

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22207   Accepted: 9846   Special Judge ...

  4. Codeforces Round #316 (Div. 2)

    A. Elections time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  5. Apache HTTP Server mod_dav.c 拒绝服务漏洞(CVE-2013-1896)

    漏洞版本: Apache HTTP Server < 2.2.25 漏洞描述: CVE ID:CVE-2013-1896 Apache HTTP Server是一款流行的WEB服务器 Apach ...

  6. -_-#【CSS】注释

  7. 【转】如何在github上fork一个项目来贡献代码以及同步原作者的修改 -- 不错

    原文网址:http://www.cnblogs.com/astwish/articles/3548844.html 作为一个IT人,通过github进行学习是最快的成长手段.我们可以浏览别人的优秀代码 ...

  8. Delphi WebService连接数据库

    1. 图如下: 个人测试  客户端 1. 2.

  9. C#调用Exe文件的方法及如何判断程序调用的exe已结束

    很简单的代码就可以实现C#调用EXE文件,如下: 引入using System.Diagnostics; 调用代码: Process.Start(exe文件名); 或直接 System.Diagnos ...

  10. [转]sleep和wait的区别

    http://www.cnblogs.com/plmnko/archive/2010/10/15/1851854.html from:http://nneverwei.javaeye.com/blog ...