Spring 学习笔记2 Spring开发环境搭建
来源:互联网 发布:炫舞按键精灵源码 编辑:程序博客网 时间:2024/06/06 01:33
新建一个Java工程:
工程需要依赖包:
需要的几个类:
package com.itest;public interface PersonService {public abstract void save();}
需要的类实现:
package com.itest.impl;import com.itest.PersonService;public class PersonServiceBean implements PersonService {/* (non-Javadoc) * @see com.itest.impl.PersonService#save() */@Overridepublic void save(){ //实现软件过程之间的解耦,要使用接口编程,对应这个方法抽取出一个接口 // 点击bean 右键 -》refactor -> extrac interface//move 可将类进行移动 System.out.println("我是save()方法"); }}
需要的配置文件:
<?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:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:ehcache="http://www.springmodules.org/schema/ehcache" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd"> <!-- 手动增加schema 进行提示windows ->preference->myeclipse->file and editors->xml-> xmlcatalog 点击 add 之后 添加spring-beans-2.5.xsd --> <!-- id 属性是xml 本省特性的不能 包含特殊字符的 但是name 可以包含特殊字符的--> <bean id="personService" class="com.itest.impl.PersonServiceBean"></bean></beans>
测试类:
package junit.test;import static org.junit.Assert.*;import org.junit.Test;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import com.itest.PersonService;public class SpringTest {@Testpublic void test() {//fail("Not yet implemented");//寻找spring 配置路径一般有两种方式,一个是类路径,一个是文件系统路径 //一般采用 类路径的方法 并且可以传入多个spring 配置文件 new String[]//ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"beans.xml"});ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml"); // 依赖对象的传感是由 spring 来进行维护的 返回的object类型需要类型转换PersonService personService= (PersonService) ctx.getBean("personService");System.out.println("hhh"); personService.save();}}
测试结果:
0 0
- Spring 学习笔记2 Spring开发环境搭建
- Spring学习笔记02---搭建开发环境
- Spring学习笔记(一)环境搭建和测试开发环境
- Spring学习笔记(一)环境搭建和测试开发环境
- Spring学习笔记 搭建环境
- Java框架学习笔记——Spring开发环境搭建
- Spring 4 学习笔记-环境搭建
- 搭建Spring开发环境
- 搭建spring开发环境
- 搭建Spring开发环境
- Spring开发环境搭建
- spring自学笔记-搭建与测试Spring的开发环境
- Spring.NET学习笔记2--环境搭建(基础篇)
- Spring学习环境搭建
- Spring学习笔记(一)Spring环境搭建
- spring(2)_开发环境搭建
- spring2.5.6学习笔记三:搭建与测试Spring的开发环境
- Spring MVC 3学习笔记+教程(一)开发环境搭建和HelloWorld程序
- JavaScript中事件处理
- 动态规划-矩阵链乘法(2)
- POJ3258——River Hopscotch(二分)
- vi基本常用命令
- 一个iOS程序员的BAT面试经验
- Spring 学习笔记2 Spring开发环境搭建
- php的cookie和session小应用
- linux下实用的指令
- leetcode51&52 N-Queens
- Swift如何检测iCloud已登录(在线)
- codeforces Round 373 div2 C. Efim and Strange Grade 模拟+ priority_queue
- ArrayList 和 LinkedList的遍历性能差异
- 1227: Gang Black and Gang White
- 关于Ubuntu