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 ...
随机推荐
- 【20181024T1】小C的数组【二分+dp】
题面 [正解] 题目求最大的最小,可以二分 设\(f_i\)表示第i个数不改满足条件需要改多少个 可以从j转移,那么[j+1,i]的均匀摊开后的差值应该在范围内 容易推出方程: \(f_i=min_{ ...
- bzoj 3900: 交换茸角
3900: 交换茸角 Description 动物园里有 n 头麋鹿.每头麋鹿有两支茸角,每支茸角有一个重量.然而,一旦某头麋鹿上 两支茸角的重量之差过大,这头麋鹿就会失去平衡摔倒.为了不然这种悲剧发 ...
- 微软笔试Highway问题解析
High way 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 In the city, there is a one-way straight highway ...
- 【个人专用&入门级】LAMP一键安装包
最近自学了下Shell编程,也算是入门吧!按照如下教程,编译安装了LAMP(Apache-2.4.6 + MySQL-5.5.25 + PHP-5.3.27) CentOS6.3编译安装LAMP(1) ...
- MathType中带上下标字符不对其
如图,上面的好看,下面的就不好看的. 上面的图使用下图下面的形式,下面的图是用的是上面的形式. 如图可以看出,右侧的更好. 比如UiTVj这样的,需要分别都用下面的形式,不能UiT用上面的,Vj直接输 ...
- vs2017 新建Class 文件时,自动添加作者版权声明注释
1.用文本打开,在其头部加上 “C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ItemTempl ...
- DELPHI开发LINUX桌面程序
DELPHI开发LINUX桌面程序 DELPHI官方目前为止尚不能开发LINUX桌面程序. 但三方控件FmxLinux(商业控件)是可以的.网上有破解版本.
- WebSocket 是什么原理?为什么可以实现持久连接?(转载)
本文转载自知乎,来源如下: 作者:Ovear链接:https://www.zhihu.com/question/20215561/answer/40316953来源:知乎著作权归作者所有.商业转载请联 ...
- NetBiosDomainNamesEnabled与SharePoint User Profile Service Application
本文中的内容转自参考资料中的文章. 如果域的NetBios名字跟Fully Qualified Domain Name不同的话, 那么就需要开启UPA的NetBiosDomainNamesEnab ...
- Windows安装和配置Tomcat
1 从http://tomcat.apache.org下载Tomcat压缩包,我这里下的版本是7.0.67. 2 将Tomcat压缩包解压缩到任意路径下,我这里的解压缩路径为E:\tomcat-7 ...