Spring 框架的搭建及测试
1、项目结构如下:

2、com.sxl.pojos==》Student.java
package com.sxl.pojos;
public class Student {
private int sid;
private String name;
private String pass;
public int getSid() {
return sid;
}
public void setSid(int sid) {
this.sid = sid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}
}
3、com.sxl.dao==》StudentDao.java
package com.sxl.dao;
import com.sxl.pojos.Student;
public class StudentDao {
public boolean addStudent(Student s) {
System.out.println("添加学生啊:"+s.getSid()+";"+s.getName()+";"+s.getPass());
return false;
}
}
4、com.sxl.service==》StudentService.java
package com.sxl.service; import com.sxl.dao.StudentDao;
import com.sxl.pojos.Student; public class StudentService {
private StudentDao mydao;
public StudentService() {
//dao=new StudentDao(); } public boolean addUser(Student stu) {
mydao.addStudent(stu);
return false;
} //IOC注入:1.set方式。2.构造函数方式
public StudentDao getMydao() {
return mydao;
} public void setMydao(StudentDao mydao) {
this.mydao = mydao;
}
}
5、com.sxl.tests==》TestSpring.java
package com.sxl.tests;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import com.sxl.pojos.*;
import com.sxl.service.StudentService; public class TestSpring { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml"); Student s=(Student) context.getBean("stu");
s.setSid(1);
s.setName("aaa");
s.setPass("123"); StudentService ss=(StudentService) context.getBean("service");
ss.addUser(s); Student s2=(Student) context.getBean("stu");
s2.setSid(2);
s2.setName("vvv");
s2.setPass("123"); System.out.println(s.getSid()+";"+s.getName()+","+s.getPass());
System.out.println(s2.getSid()+";"+s2.getName()+","+s2.getPass());
}
}
6、配置文件: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"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="stu" class="com.sxl.pojos.Student" scope="prototype"></bean> <bean id="dao" class="com.sxl.dao.StudentDao"></bean> <bean id="service" class="com.sxl.service.StudentService">
<property name="mydao" ref="dao"></property>
</bean>
</beans>
7、测试结果:

Spring 框架的搭建及测试的更多相关文章
- Spring框架学习-搭建第一个Spring项目
步骤一:下载Spring开发包. 官网:https://spring.io/ 下载地址:https://repo.spring.io/libs-release-local/org/ ...
- 【Spring】浅析Spring框架的搭建
c目录结构: // contents structure [-] Spring是什么 搭建Spring框架 简单Demo 1,建立User类 2,建立Test类 3,建立ApplicationCont ...
- SSM框架的搭建与测试
关于框架的搭建无非就是 框架所依赖的jar包,然后就是关于各个框架的配置文件: 下面我们来看下不同层的依赖的jar包以及各个配置文件: 首先pojo这一层只需要依赖parent聚合工程 mapper层 ...
- 【Spring】Spring之浅析Spring框架的搭建
Spring是什么 Spring是一个开源的容器框架,用于配置bean并且维护bean之间关系的.其主要的思想就是IOC(Inversion Of Control,控制反转)或者称作DI(Depend ...
- Spring框架环境搭建
环境要求:jdk 1.7 及以上.Spring版本:4.3.2 1.建立普通的java 工程 2.新建lib目录,并将一下5个核心jar包拷贝过来,并加入classpath中 下载地址: http: ...
- SSH框架的搭建和测试(Spring + Struts2 + Hibernate)
SSH框架实现了视图.控制器.和模型的彻底分离,同时还实现了业务逻辑层与持久层的分离. Spring实现了MVC中的 Controller的功能,Struts实现Web视图的功能,Hibernate则 ...
- SSM框架的搭建和测试(Spring+Spring MVC+MyBatis)
Spring MVC:MVC框架,通过Model-View-Controller模式很好的将数据,业务与展现进行分离. MyBatis:数据持久层框架 我这里使用的是MyEclipse 2016 CI ...
- (01)hibernate框架环境搭建及测试
---恢复内容开始--- 1.创建javaweb项目 2.导包 hibernate包 hibernate\lib\required\*.jar 数据库驱动包 mysql-connector-java- ...
- Spring环境的搭建与测试 (spring2.5.6)
这里是采用的视频里面的spring版本 下载spring2.5.6, 然后进行解压缩,在解压目录中找到下面jar文件,拷贝到类路径下 dist\spring.jar lib\jakarta-commo ...
随机推荐
- 【扫描线】Gym - 101190E - Expect to Wait
假设初始人数为0, 将每个时刻在等待的人数写下来,就是求个和. 如果纵坐标看成人数,横坐标看成时间,就是求个面积. 因为初始人数不一定为零,所以离线后扫描线即可回答所有询问. #include< ...
- 浅谈js对象及对象属性
对象: ECMA-262把对象定义为 :无序属性的集合,其属性可以包含基本值,对象或者函数. 严格来讲,这就相当于说对象是一组没有特定顺序的值.对象的每一个属性或方法都有一个名字,而每个名字都映射到一 ...
- 解决 javax.net.ssl.SSLException: java.lang.RuntimeException: Could not generate DH keypair
解决这个异常的重点就在于下载两个jar包: bcprov-ext-jdk15on-1.52 bcprov-jdk15on-1.52 传送门:https://stackoverflow.com/ques ...
- 星际争霸 虚空之遗 人族5BB 操作流程
人族5BB rush timing 3min-3min30 一波战术,对面双开不侦察应该就GG了. 14农民BS,建议在第一个BS后的100矿,马上接上一个BS堵口,基本上对面是侦察不到的,特别是内双 ...
- UVA 10163 - Storage Keepers(dp)
本文出自 http://blog.csdn.net/shuangde800 题目链接: 点击打开链接 题意 有n个仓库,让m个人来看管.一个仓库只能由一个人来看管,一个人可以看管多个仓库. 每个人 ...
- dotnet若干说明图片
- C,C++开源项目中的100个Bugs
俄罗斯OOO Program Verification Systems公司用自己的静态源码分析产品PVS-Studio对一些知名的C/C++开源项目,诸如Apache Http Server.Chro ...
- jenkins平台通过maven方式使用sonar报大量关于html/css/js的错误解决办法
1.如果项目只关注java的源代码扫描,可以在sonar上把检查html.css.js的插件卸载,让后重启sonar避免不需要检查的内容报错误
- Hibernate3的jar包
一.hibernate3包说明 说明: Hibernate 软件包中的Hibernate3.jar 是我们需要使用的Hibernate 工具,其他引用的 Jar 文件位于lib 子目录下,Hibern ...
- SSH远程连接连接其他主机,等待时间过长的原因。
ssh远程连接登录到其他主机,输入登录用户名,等待时间很长时间,然后才出现输入密码的提示.导致这样时间过长,太慢了的原因有两个.(1)当使用ssh远程登录到某个IP时,这个IP的主机系统会读取/etc ...