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.测试结果

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

  1. 项目SpringMVC+Spring+Mybatis 整合环境搭建(1)-> Spring+Mybatis搭建

    目录结构 第一步:web.xml 先配置contextConfigLocation 对应的application-context.xml文件 打开webapp\WEB-INF\web.xml, 配置s ...

  2. SSH环境搭建之Hibernate环境搭建篇

    SSH环境搭建之Hibernate环境搭建篇 搭建有两种方式: 1.使用IntelliJ IDEA或者MyEclipse的逆向工程(关系模型 -> 对象模型),我使用的是IntelliJ IDE ...

  3. 移动商城第三篇【搭建Mybatis和Spring环境、编写Dao、Service在Core模块】

    Mybatis和Spring环境搭建 由于我们的所编写的dao层.service代码可能前台和后台都需要用到的,因此我们把环境搭建在core模块中 逆向工程 首先,我们要做的就是品牌管理,我们首先来看 ...

  4. Maven搭建struts2+spring+hibernate环境

    Maven搭建struts2+spring+hibernate环境(一) 本文简单的使用STS的自带的maven插件工具搭建ssh(struts2+spring+hibernate)开发环境,图文并茂 ...

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

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

  6. spring环境的搭建及作用和定义<一>

    问题?spring的定义及作用.spring的环境搭建 一.spring的定义及作用 1.spring由Rod Johnson创建的一个开源框架,它是为了解决企业应用开发的复杂性而创建的.框架的主要优 ...

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

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

  8. 适合初学者的一个分布式环境搭建过程(spring boot + zookeeper + dubbo + mybatis + mysql)

    本人也是才开始接触 阿里巴巴的开源分布式框架 dubbo,因为现在微服务框架 spring boot也非常的火,然后结合dubbo的官网搭建这个开发环境. 一.首先 zookeeper作为集群管理服务 ...

  9. 使用IntelliJ IDEA和Maven管理搭建Web开发环境(以Spring MVC为例)(二)

    前言:在使用IntelliJ IDEA和Maven管理搭建Web开发环境(以Spring MVC为例)(一)中已经介绍了如何对web基础环境进行搭建,这里主要演示,如何对spring环境进行搭建,然后 ...

随机推荐

  1. 最新 科大讯飞java校招面经 (含整理过的面试题大全)

    从6月到10月,经过4个月努力和坚持,自己有幸拿到了网易雷火.京东.去哪儿.科大讯飞等10家互联网公司的校招Offer,因为某些自身原因最终选择了科大讯飞.6.7月主要是做系统复习.项目复盘.Leet ...

  2. zookeeper的shell下操作

    zookeeper的shell下操作 进入%ZK_HOME%/bin 执行zkCli.sh [-server ip:port] #如不指定,则连接本机   创建: create [-s] [-e] p ...

  3. 对于大于等于3的整数n,在区间【n,3/2 * n】中一定存在一个素数

    对于大于3的整数n,在区间[n,3/2 * n]中一定存在一个素数

  4. 【转帖】Webmin 安装 (centos7 rpm 方式)

    https://www.cnblogs.com/osfipin/p/5948803.html 这两天公众号都在手这个小工具, 今天早上试了下 挺好用的 还看到了启动 samba 的方法. 一会儿 再学 ...

  5. 【AtCoder】AGC010

    AGC010 A - Addition 如果所有数加起来是偶数那么一定可以,否则不行 #include <bits/stdc++.h> #define fi first #define s ...

  6. 【AtCoder】ARC060

    ARC060 C - 高橋君とカード / Tak and Cards 每个数减去A,然后转移N次,每次选或不选,最后是和为0的时候的方案数,负数可以通过把所有数右移2500做到 #include &l ...

  7. hdu 1029 求出现次数过半的数

    题目传送门//res tp hdu 已知必定存在一个元素出现次数超过一半,考虑用栈 若当前元素等于栈顶元素,入栈,反之出栈,并将当前元素入栈 最终的栈顶元素即是所求 #include<iostr ...

  8. dedecms发布文章时间显示多少分钟前

    /**文章发布多少时间前*/function tranTime($time) { $rtime = date("m-d H:i",$time); $htime = date(&qu ...

  9. Foo Fighters CodeForces - 1148F

    大意: 给定$n$个二元组$(val_i,mask_i)$. 保证$\sum val_i$不为$0$. 要求选择一个数$s$, 对于每个二元组$(val_i,mask_i)$, 若$s\& m ...

  10. MySql 8.0.11 客户端连接失败:2059 - Authentication plugin 'caching_sha2_password' cannot be loaded: ....

    近期,换了新笔记本,重新安装了MySql数据库和客户端工具Navicat Premium 12.我是从官网上下载的MySql数据库,版本为8.0.11,链接:https://dev.mysql.com ...