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

一、引入Spring所使用的JAR文件

二、在src目录下创建beans.xml(Spring的容器文件)

 <?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"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> </beans>

三、创建测试类并测试

1.实体类 TestService.java

 package com.xiaonei.test;

 /**
* Created by zhangshengjian on 2017/1/19.
*/
public class TestService { private String name; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
}

2.将实体类对应内容配置到beans.xml文件中

 <bean id="testService" class="com.xiaonei.test.TestService">
<property name="name" value="ok"/>
</bean>

3.测试类 TestApp.java

 package com.xiaonei.test;

 import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; /**
* Created by zhangshengjian on 2017/1/19.
*/
public class TestApp { public static void main(String[] args) {
ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
TestService testService = (TestService) ac.getBean("testService");
System.out.println(testService.getName());
}
}

4.测试结果

最新文章

  1. [No0000AD]7z源码完全移植至Visual Studio 2015
  2. unrecognized selector sent to instance
  3. AWS-CDH5.5安装-安装
  4. nginx之location
  5. HTTP Basic Authentication
  6. [改善Java代码]覆写equals方法时不要识别不出自己
  7. exit和abort都是用来终止程序的函数
  8. Linux学习之第十九、条件判断
  9. 初识google多语言通信框架gRPC系列(三)C#中使用gRPC
  10. String、StringBuffer、与StringBuilder的区别
  11. Css(常用的特殊效果)
  12. hive中left/right join on连接中and与where的使用问题
  13. hyperscan简单学习(2)
  14. day05 数据基本类型及内置方法:字符串str、列表list
  15. 奇怪吸引子---LiuChen
  16. 怎样从外网访问内网WebLogic?
  17. 在thinkphp里面执行原生的sql语句
  18. 计算概论(A)/基础编程练习1(8题)/5:鸡兔同笼
  19. config配置中心之自动刷新
  20. Oracle中查询主键、外键、sequence、表基本信息等

热门文章

  1. Linear regression with one variable - Model representation
  2. 01.04 linux命令(2
  3. OpenCV_CS.测试
  4. eduSOHO 首页模板 全部课程模块代码
  5. (模板)求逆矩阵luoguP4783
  6. Java集合框架——Set接口
  7. B7. Concurrent 锁的分类
  8. [转帖]强大的strace命令用法详解
  9. CentOS7.0 测试环境准备过程
  10. 整体二分(模板一)静态区间第K大