Spring 环境搭建
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 环境搭建的更多相关文章
- Spring环境搭建之:导入jar包、配置文件名称及放置位置
Spring环境搭建之:导入jar包.配置文件名称及放置位置 现在项目开发中spring框架应用的还是比较多的,自己用的还不太熟练,每次用的时候总配置半天,总有些配置弄错,就找个时间总结以下,方便以后 ...
- 【Spring学习笔记-1】Myeclipse下Spring环境搭建
*.hl_mark_KMSmartTagPinkImg{background-color:#ffaaff;}*.hl_mark_KMSmartTagBlueImg{background-color:# ...
- 【Spring环境搭建】在Myeclipse下搭建Spring环境-web开发
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" ...
- Spring之Spring环境搭建
Spring之Spring环境搭建 一.什么是Spring? Spring框架是由于软件开发的复杂性而创建的.Spring使用的是基本的JavaBean来完成以前只可能由EJB完成的事情.然而,Spr ...
- SSH环境搭建之Spring环境搭建篇
SSH环境搭建之Spring环境搭建篇 一.引入Spring所使用的JAR文件 二.在src目录下创建beans.xml(Spring的容器文件) <?xml version="1.0 ...
- Spring环境搭建及简单demo
1. Spring框架简介(以下这段话可用于面试求职) Spring为JavaEE开发提供了一个轻量级的解决方案,主要表现为, IOC(或者叫做DI)的核心机制,提供了bean工厂(Spring容器) ...
- eclipse Spring环境搭建 spring tool suite
1.期初用intellij社区版,发现收费版才能开发Java EE. 2.使用eclipse按照网上的教程,在help->eclipse marketplace中搜索sts安装spring工具套 ...
- 01、Spring环境搭建
环境:SpringSource-Tool-3.9.9.Eclipse4.10.0 首先,我们需要解决的是Spring包的问题,我看了百度.CSDN很多都是直接一上来随便丢个包就可以安装了,搞得我弄了一 ...
- 一、spring 环境搭建
一.springtoolSuite4下载 1.概述 Spring Tools 4 是适用于您最喜欢的编码环境的下一代 Spring 工具.它主要从头开始重建,为开发基于 Spring 的企业应用程序提 ...
- spring环境搭建需要的插件-------Spring Tool Suite™ Downloads
下载地址http://spring.io/tools/sts/all 上面的是集成了eclipse的,所以文件比较大,下面的是单独的插件,下载之后打开eclipse,help->installN ...
随机推荐
- J2EE和EJB有什么关系?
其实j2EE就是java的企业版,与javaSE(标准版)有是有区别的,所以运行环境会有差异(简单点可以说,这是两组不同的接口),我们一般所熟悉的tomcat仅仅只实现了j2ee的一小部分规范,它只是 ...
- 如何给div加一个边框border样式
如何给div加一个边框样式? 对div盒子加一个边框样式很简单只需要使用border板块样式即可. 一.虚线与实线边框 边框虚线样式:dashed 边框实现样式:solid border:1px da ...
- 用 SQL 脚本读取Excel 中的sheet数量及名称
-- Get table (worksheet) or column (field) listings from an excel spreadsheet -- 设置变量 declare @linke ...
- linux配置端口转发
一.使用rinted进行端口转发 将10.50.13.13 80请求转到10.50.13.11 80上 1.安装rinetd $ tar zxf rinetd.tar.gz $ cd rinetd $ ...
- 搜索(三分):HDU 3400 Line belt
Line belt Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- IOS的 testflight测试设置
管理员邀请参与者 1.登录开发者账号https://developer.apple.com/account 2.进入后,点击ituns connect 3.点击进入用户和职能 4.在用户栏点击添加按钮 ...
- datagridview bindingsource
调用bindindsource的ResetBindings() 方法
- WCF—Binding
原文地址:http://www.cnblogs.com/jams742003/archive/2010/01/13/1646379.html Binding描述了哪些层面的信息 一个Binding包含 ...
- 洛谷2344 奶牛抗议(DP+BIT+离散化)
洛谷2344 奶牛抗议 本题地址:http://www.luogu.org/problem/show?pid=2344 题目背景 Generic Cow Protests, 2011 Feb 题目描述 ...
- hdu 4608 I-number 大整数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4608 #include <cstdio> #include <cmath> # ...