spring 1

 1 使用spring可以使用简单的javabean实现以前EJB才能实现的功能

 2 IOC(DI)和AOP--->IOC控制反转约等于依赖注入,AOP是面向切面变成,这俩是spring的核心

 3 轻量级非侵入性,不需要继承任何父类

 4 spring是一个一站式的框架:可以整合很多其他第三方框架(实际上spring自己有spring MVC以及持久层spring JDBC)

 5 spring 模块:

1)最底层是核心容器

core container :beans、core、context(上下文)、spEL(spring 的el表达式)

2)AOP 、Aspect、instrumentation、messaging(消息)

3)懒,下回再写

 helloworld例子:


1 HelloWorld.java

package mdd.study.beans;

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

public class Test {
public static void main(String[] args) {
//创建对象和胃属性赋值交给spring来完成

//1 创建spring 的IOC容器对象
ApplicationContext ctx=
new ClassPathXmlApplicationContext("applicationContext.xml");
//2 从IOC容器中获取bean实例
HelloWorld hello=(HelloWorld)ctx.getBean("helloWorld");
//调用hello方法
hello.hello();
}
}

2 Test.java

package mdd.study.beans;


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

public class Test {
public static void main(String[] args) {
//创建对象和胃属性赋值交给spring来完成

//1 创建spring 的IOC容器对象
ApplicationContext ctx=
new ClassPathXmlApplicationContext("applicationContext.xml");
//2 从IOC容器中获取bean实例
HelloWorld hello=(HelloWorld)ctx.getBean("helloWorld");
//调用hello方法
hello.hello();
}
}


3 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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- 配置bean -->
<bean id="helloWorld" class="mdd.study.beans.HelloWorld">
<property name="name" value="hanmeimei"></property>
</bean>
</beans>

4 lib包

commons-logging.jar
spring-beans-4.0.4.RELEASE.jar
spring-context-4.0.4.RELEASE.jar
spring-core-4.0.4.RELEASE.jar
spring-expression-4.0.4.RELEASE.jar

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值