Spring介绍(一)

     Spring简介

Spring特点

      Spring是一个轻量级的locAOP容器框架。

           轻量级:从大小及系统开支上说。且Spring是非侵入式的(基于Spring开发的系统中对象一般不依赖于Spring的类)

           反向控制:使用loc对象是被动接收依赖而不是主动去找(容器在实例化对象是主动将其依赖类注入给它)

           面向切面:将业务逻辑从系统服务中分离,实现内聚开发。系统对象只做其该做的业务业务逻辑不负责其他系统问题(如日志和事务支持)

           容器:包括且管理系统对象的生命周期和配置,通过配置设定Bean是单一实例还是每次请求产生一个,并设定Bean之间的关联关系

           框架:使用简单组件配置组合成一个复杂的系统,系统中的对象是通过XML文件配置组合起来的,且Spring提供了很多基础功能(事务管理,持久层集成等)

Spring 模块

        Spring框架由7个模块组成

          核心容器:提供了基础功能。包括BeanFactory类(Spring框架的核心,采用工厂模式实现Loc

          应用上下文模块:扩展了Beanfactory,添加了对I18N(国际化)、系统生命周期事件及验证的支持,并提供许多企业级服务,如电子邮件、JNDI访问、EJB集成、远程调用及定时服务,并支持与模板框架(如VelocityFreeMarker)的集成。

          AOP模块:对面向切面提供了丰富的支持模式Spring应用系统开发切面的基础;并引入metadata编程

          JDBCDAO模块

          O/R映射模块:

          Web模块:建立在应用上下文模块的基础上,提供了合适web系统的上下文,另外,该模块支持多项面web任务,如透明处理多文件上传请求,自动将请求参数绑定到业务对象中等。

          MVC框架:

       所有模块都是建立在核心容器上的,容器规定如何创建、配置和管理Bean,以及其细节。

 Spring简单示例:

      程序清单 Greeting Serice 接口将实现从接口中分离出来

  package cn.csdn.service;

public interface GeetService {
void geetsay();
}

  程序清单 GreetingServiceImp.java负责打印问候语

package cn.csdn.service;

public class GeetServiceImp implements GeetService{
                private String say;
	            @Override
	            public void geetsay() {
		            System.out.println("我没有说"+say);
		
	               }

	              public void setSay(String say) {
		       this.say = say;
	             }
 
}

  程序清单: 在Spring中配置Hello

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=http://www.springframework.org/schema/beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
	<bean id="geetServiceImp" class="cn.csdn.service.GeetServiceImp">
	   <property name="say" value="hello"></property>
	
	</bean>
</beans>

 程序清单:hello示例的主类

  package cn.csdn.test;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cn.csdn.service.GeetServiceImp;

public class GeetTest {
	@Test
	public void test1() {
		ApplicationContext ac = new ClassPathXmlApplicationContext(
				"applicationContext.xml");
		GeetServiceImp a = (GeetServiceImp) ac.getBean("geetServiceImp");
		a.geetsay();
	}
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值