日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

spring 环境

發布時間:2023/12/9 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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

總結

以上是生活随笔為你收集整理的spring 环境的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。