Spring的两个核心部分
IOC:控制反转,把创建对象的过程交给Spring进行管理
Aop:面向切面,不修改源代码也能进行功能增强
Spring框架的特点
1.方便解耦,简化开发
2.Aop编程的支持
3.方便程序的测试,支持junit4
4.方便集成各种其他框架
5.降低javaEE api的使用难度
6.方便进行事务的操作
public class Introduction {
public void add() {
System.out.println(
"add..."
);
}
}
<?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">
<!--配置user对象创建-->
<!--对象user的创建-->
<bean id="user" class="day501_intro.Introduction">
</bean>
</beans>
public class TestSpring5 {
@Test
public void test01(){
//加载spring的配置文件
ApplicationContext context=new ClassPathXmlApplicationContext("bean1.xml");
//获取配置创建的对象
Introduction user = context.getBean("user", Introduction.class);
System.out.println(user);
user.add();
}
}