spring 环境

引用:http://www.189works.com/article-96241-1.html

准备阶段:

到Spring官网下载所需的API包,其中spring-framework-X.X.X.RELEASE-with-docs.zip压缩包需要下载,里面的dist目录下有所需的API,还有一个是com.springsource.org.apache.commons.logging-1.1.1.jar需要下载,下载地址:http://www.springsource.org/download/community?project=Spring%2520Framework

图解:

我已经下载还了所需的API包,版本是3.1.1的,可以直接下载使用:http://pan.baidu.com/share/link?shareid=28989&uk=2198762756

 

测试阶段:

项目结构:

所需包导入:

其实有些jar包在这个测试中是不需要的,不过为了方便也不想逐一测试了。

 

com.sunflower.pojo.Student:

 1 package com.sunflower.pojo; 2  3 /** 4  *  学生实体类 5  */ 6 public class Student { 7     private String name; 8     private int age; 9 10     public String getName() {11         return name;12     }13 14     public void setName(String name) {15         this.name = name;16     }17 18     public int getAge() {19         return age;20     }21 22     public void setAge(int age) {23         this.age = age;24     }25 26 }

 这个类在这个测试中没有实际用途,只不过让这个测试看起来有这个意思。

 

com.sunflower.yuan.dao.StudentDAO:

 1 package com.sunflower.yuan.dao; 2  3  4 /** 5  * 学生数据存取接口,操作底层数据 6  */ 7 public interface StudentDAO { 8     public void saveStudent(); 9 10     public void removeStudent();11 }

 

com.sunflower.yuan.daoimp.StudentDAOImp:

 1 package com.sunflower.yuan.daoimp; 2  3 import com.sunflower.yuan.dao.StudentDAO; 4  5 /** 6  * 学生数据存取实现类 7  */ 8 public class StudentDAOImp implements StudentDAO { 9 10     @Override11     public void removeStudent() {12         System.out.println("Student deleted! Spring test success");13     }14 15     @Override16     public void saveStudent() {17         System.out.println("Student saved! Spring test success");18     }19 20 }

 

com.sunflower.yuan.service.StudentService:

 1 package com.sunflower.yuan.service; 2  3 /** 4  * 学生业务处理接口 5  */ 6 public interface StudentService { 7     public void saveStudent(); 8  9     public void removeStudnet();10 }

 

 com.sunflower.yuan.serviceimp.StudentServiceImp:

 1 package com.sunflower.yuan.serviceimp; 2  3 import com.sunflower.yuan.dao.StudentDAO; 4 import com.sunflower.yuan.daoimp.StudentDAOImp; 5 import com.sunflower.yuan.service.StudentService; 6  7 /** 8  * @author Caihanyuan 9  * @time 2012-9-11 下午07:47:5510  */11 public class StudentServiceImp implements StudentService {12     private StudentDAO studentDao = new StudentDAOImp();13 14     @Override15     public void removeStudnet() {16         studentDao.removeStudent();17     }18 19     @Override20     public void saveStudent() {21         studentDao.saveStudent();22     }23 24 }

 

 com.sunflower.yuan.test.Test:

 1 package com.sunflower.yuan.test; 2  3 import org.springframework.context.ApplicationContext; 4 import org.springframework.context.support.ClassPathXmlApplicationContext; 5  6 import com.sunflower.yuan.service.StudentService; 7 import com.sunflower.yuan.serviceimp.StudentServiceImp; 8  9 /**10  * @author Caihanyuan11  * @time 2012-9-11 下午07:53:5712  */13 public class Test {14     public static void main(String[] args) {15         ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");16         17         //得到注入的bean18         StudentService studentService = context.getBean("studentService", StudentServiceImp.class);19         studentService.saveStudent();20         studentService.removeStudnet();21     }22 }

第15行是通过解析xml配置文件获取Spring容器,第18行得到在配置文件中注入到Spring中的对象,注入的对象不能是接口。

 

applicationContext.xml:

1 <?xml version="1.0" encoding="UTF-8"?>2 <beans3     xmlns="http://www.springframework.org/schema/beans"4     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"5     xmlns:p="http://www.springframework.org/schema/p"6     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">7     8     <bean id="studentService" class="com.sunflower.yuan.serviceimp.StudentServiceImp"></bean>9 </beans>

 

转载于:https://www.cnblogs.com/sode/archive/2012/09/17/2688802.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/409548.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

php 上传多文件_php 多文件上传的实现实例

首先向大家讲解一下实现的方法。要实现多文件上传&#xff0c;我们可以在form表单中添加多个input file域&#xff0c;然后将这些input file的name属性设置为相同的名称且使用数组的形式命名&#xff0c;例如filename[]。至于文件上传的php代码和单个文件上传是一样的道理。下面…

JavaScript代码优化实战之一:缓存变量,关键字过滤

无意中看到某网站的一段JS代码&#xff1a; 1 function clearSearchText(){2 var searchtext document.getElementById("searchwordl").value3 document.getElementById("searchwordl").value"";4 }5 function replaceALL(){6 va…

html.parser python_python模块之HTMLParser

HTMLParser是python用来解析html的模块。它可以分析出html里面的标签、数据等等&#xff0c;是一种处理html的简便途径。 HTMLParser采用的是一种事件驱动的模式&#xff0c;当HTMLParser找到一个特定的标记时&#xff0c;它会去调用一个用户定义的函数&#xff0c;以此来通知程…

php 5.4 aws,使用 Amazon EC2 管理 AWS SDK for PHP 实例 - 适用于 PHP 的 AWS 开发工具包

AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异&#xff0c;请参阅中国的 AWS 服务入门。本文属于机器翻译版本。若本译文内容与英语原文存在差异&#xff0c;则一律以英文原文为准。使用 Amazon EC2 管理 AWS SDK for PHP 实例以下示例演示如何&…

python图片分类毕业设计成果报告书_毕业设计成果报告书模板.doc

毕业设计成果报告书成 果&#xff1a;姓 名&#xff1a;学 号&#xff1a;专 业&#xff1a;区 队&#xff1a;指导老师&#xff1a;二〇XX年X月目  录TOC \o "1-3" \h \z \u HYPERLINK \l "_Toc432664597" 一、选题背景 PAGEREF _Toc432664597 \h 1HYPE…

常用正则表达式例子

1。^\d$  //匹配非负整数&#xff08;正整数 0&#xff09; 2。^[0-9]*[1-9][0-9]*$  //匹配正整数 3。^((-\d)|(0))$  //匹配非正整数&#xff08;负整数 0&#xff09; 4。^-[0-9]*[1-9][0-9]*$  //匹配负整数 5。^-?\d$    //匹配整数 6。^\d(\.\d)?$  //…

msf生成php,使用msfpayload生成后门(asp,aspx,php,jsp,exe)等

msfpayload与msfencode参数说明执行msfpayload -h查看都有哪些参数执行msfencode -h查看都有哪些参数生成backdoor类型可以生成asp、aspx、php、jsp、war、exe等多种类型,下面介绍的使用方法就不一一测试了.msfpayload生成linux backdoor目标机器运行linux2,本机监听下端口,使用…

概括ADO.NET数据库连接的所有形式(基础)

概括ADO.NET数据库连接的所有形式(基础&#xff09; 可能大家进来会喷笔者&#xff0c;这么基础的知识还放在首页。那么笔者就要问问大家了&#xff0c;你可能熟悉其中部分数据库读取的形式&#xff0c;但是熟悉全部的估计很少&#xff0c;或者你完全忘记了&#xff0c;因为这些…

python 进程池不足_python 进程池pool简单使用

平常会经常用到多进程&#xff0c;可以用进程池pool来进行自动控制进程&#xff0c;下面介绍一下pool的简单使用。需要主动是&#xff0c;在Windows上要想使用进程模块&#xff0c;就必须把有关进程的代码写if __name__ ‘__main__’ :语句的下面&#xff0c;才能正常使用Wind…

php opendir 不能用,PHP opendir() 函数

打开一个目录&#xff0c;读取它的内容&#xff0c;然后关闭&#xff1a;$dir "/images/";// Open a directory, and read its contentsif (is_dir($dir)){if ($dh opendir($dir)){while (($file readdir($dh)) ! false){echo "filename:" . $file . &q…

程序集

程序集 在C#中&#xff0c;我们要使用反射&#xff0c;主要有三个方面&#xff1a; 第一&#xff0c;反射程序集&#xff0c;模块&#xff0c;类的成员以及成员的一些信息&#xff1b; 第二&#xff0c;接下来就是动态调用类的成员方法&#xff1b; 第三个方面就动态产生程序集…

从像素坐标到相机坐标_【视觉知识】机器视觉几何坐标概论

作者&#xff1a;林青春来源&#xff1a;知乎一、机器视觉几何坐标概论机器视觉系统有三大坐标系&#xff0c;分别是&#xff1a;1、世界坐标系&#xff0c;2、摄像机坐标系&#xff0c;3、图像(像素)坐标系。1、世界坐标系世界坐标系(Xw&#xff0c;Yw&#xff0c;Zw)是目标物…

php 对象 数量,php – Symfony2 / Doctrine如何在实体中存储相关对象的数量

我已经设置了一个包含测试对象的包,该对象包含许多testQuestion对象,每个对象都是一个问题和给定的答案(如果没有答案则为0).从树枝上我希望能够从测试对象中获取信息,说明有多少问题以及已经回答了多少问题.我创建了一个查询来将其从数据库中拉出来,在测试实体中我创建了2个新…

GNU make manual 翻译( 一百六十)

继续翻译 The only restriction on this sort of use of nested variablereferences is that they cannot specify part of the name of a functionto be called. This is because the test for a recognized function nameis done before the expansion of nested references.…