1、IOC:控制反转,把创建对象交给Spring进行管理。
2、Aop:面向切面,不修改源代码进行功能增强。
<?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 id="Main" class="com.Main"></bean> </beans>
import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Test { public void testadd() { //加载Spring配置文件 ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml"); //获取配置创建对象 context.getBean("Main",Main.class); } }