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 框架的搭建及测试的更多相关文章

  1. Spring框架学习-搭建第一个Spring项目

    步骤一:下载Spring开发包. 官网:https://spring.io/           下载地址:https://repo.spring.io/libs-release-local/org/ ...

  2. 【Spring】浅析Spring框架的搭建

    c目录结构: // contents structure [-] Spring是什么 搭建Spring框架 简单Demo 1,建立User类 2,建立Test类 3,建立ApplicationCont ...

  3. SSM框架的搭建与测试

    关于框架的搭建无非就是 框架所依赖的jar包,然后就是关于各个框架的配置文件: 下面我们来看下不同层的依赖的jar包以及各个配置文件: 首先pojo这一层只需要依赖parent聚合工程 mapper层 ...

  4. 【Spring】Spring之浅析Spring框架的搭建

    Spring是什么 Spring是一个开源的容器框架,用于配置bean并且维护bean之间关系的.其主要的思想就是IOC(Inversion Of Control,控制反转)或者称作DI(Depend ...

  5. Spring框架环境搭建

    环境要求:jdk  1.7 及以上.Spring版本:4.3.2 1.建立普通的java 工程 2.新建lib目录,并将一下5个核心jar包拷贝过来,并加入classpath中 下载地址: http: ...

  6. SSH框架的搭建和测试(Spring + Struts2 + Hibernate)

    SSH框架实现了视图.控制器.和模型的彻底分离,同时还实现了业务逻辑层与持久层的分离. Spring实现了MVC中的 Controller的功能,Struts实现Web视图的功能,Hibernate则 ...

  7. SSM框架的搭建和测试(Spring+Spring MVC+MyBatis)

    Spring MVC:MVC框架,通过Model-View-Controller模式很好的将数据,业务与展现进行分离. MyBatis:数据持久层框架 我这里使用的是MyEclipse 2016 CI ...

  8. (01)hibernate框架环境搭建及测试

    ---恢复内容开始--- 1.创建javaweb项目 2.导包 hibernate包 hibernate\lib\required\*.jar 数据库驱动包 mysql-connector-java- ...

  9. Spring环境的搭建与测试 (spring2.5.6)

    这里是采用的视频里面的spring版本 下载spring2.5.6, 然后进行解压缩,在解压目录中找到下面jar文件,拷贝到类路径下 dist\spring.jar lib\jakarta-commo ...

随机推荐

  1. 1.4(SQL学习笔记)分组、子查询、联结、组合查询

    一.分组 建表及数据填充语句下载:链接: https://pan.baidu.com/s/1WHYafwqKJEKq1kDwCH_Zlg 提取码: 3wy4 1.1初识分组 分组是按照某一列,将该列中 ...

  2. c99柔性数组

    变长结构体 struct test { int nSize; char data[]; // 或者 char data[0];但建议使用 char data[]; 注意:c98 时不支持柔性数组,其仅 ...

  3. LNMP一键包屏蔽PHP报错信息开启方法

    在 php-fpm.conf中的[www]下添加php_flag[display_errors] = On 重启php-fpm即可 /etc/init.d/php-fpm restart

  4. php函数前面加&符号 和 变量前面加&符号的意义

    php函数前面加&符号 和 变量前面加&符号的意义 php函数前面加&符号的意思是函数的引用返回,php函数前面加&符号有什么作用呢 function &tes ...

  5. <摘录>cocos2d-x 从环境搭建到win32项目移植android平台

    软件:cocos2d-x-2.2.3:android-ndk-r9d:adt-bundle-windows-x86_64-20131030:python-2.7.6: 1安装配置python 安装没什 ...

  6. java程序中没有错,但是项目上面显示一个红叉的解决办法

    错误信息: 报Description  Resource Path Location Type Java compiler level does not match the version of th ...

  7. [转] Moran's I

    李旭, Matlab: Moran's I原文地址 Introduction In statistics, Moran's I is a measure of spatial autocorrelat ...

  8. 完美解决“find: 路径必须在表达式之前:”

    使用find命令查找文件的时候会有如题的提示,只需略作修改即可.两种方法: ①可cd到其它目录再查找(当前目录下存在要查找的目标文件时会出现此类错误,换到其它目录下再执行相同的命令即可): ②如果目标 ...

  9. go语言基础之基础数据类型 bool类型 浮点型

    1.bool类型 示例1: package main import "fmt" func main() { var a bool a = true fmt.Println(&quo ...

  10. curl错误码大全

    CURL状态码列表 状态码 状态原因 解释 0 正常访问 访问地址未返回结果 1 错误的协议 未支持的协议.此版cURL 不支持这一协议. 2 初始化代码失败 初始化失败. 3 URL格式不正确 UR ...