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. Construct Binary Tree from Preorder and Inorder Traversal——LeetCode

    Given preorder and inorder traversal of a tree, construct the binary tree. 题目大意:给定一个二叉树的前序和中序序列,构建出这 ...

  2. 汉洛塔递归实现的思考(C语言)

    汉洛塔是古印度神话产生的智力玩具,他的玩法是,有三个柱子分别为A,B,C,A柱上面有n个盘子上面小下面大堆叠放在一起,现在要求激将A柱上的盘子全部移到C柱上面,并且一次只能移动一个盘子,必须是小盘在大 ...

  3. 数学概念——A 几何概型

    You are going from Dhaka to Chittagong by train and you came to know one of your old friends is goin ...

  4. 《University Calculus》-chaper8-无穷序列和无穷级数-等比级数

    前言:其实无穷序列和无穷级数和数列{an}以及我们接触微积分就给出的极限概念lim有着紧密的联系,它对于我们在具体的问题当中进行建模和数据分析有着非常重要的作用. 无穷序列: 最简单的一种说法,就是一 ...

  5. 【模拟】Class 解题报告

    [问题描述] 信息班这期的课将要结束了,老师要从现在班上的同学中选出比较优秀的同学进入下一期的学习.而录取标准则是将平时作业和考试一起考虑,综合成绩排在前面的则录取.经过一番思考,老师作了以下的筛选计 ...

  6. sql server 常用小知识点

    1. sql server的语法:中文要加 N select * from eVA_EMPBoard where name = N'施纪平' 而oracle的不用 2.

  7. BIGINT UNSIGNED value is out of range in … 问题的解决方法

    问题出现在CAST(value AS USIGNED)将字符串转换成数值的过程中,出现这个问题的原因是value对应的数值在BIGINT UNSIGNED 的范围内.可能的情况是value的值太大,超 ...

  8. string和stringbuffer stringbuilder的快速理解。

    这三个对象都可操作字符串,区别string定义的变量除非重新赋值,否则是不可改变的.调用string的方法不会改变,但是其他两个有对象的方法可改变,比如apend的方法,后两个区别一个是线程安全不安全 ...

  9. 九度OnlineJudge之1001:A+B for Matrices

    题目描述: This time, you are supposed to find A+B where A and B are two matrices, and then count the num ...

  10. HDOJ 1787 GCD Again(欧拉函数)

    GCD Again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...