1.Spring概述
是轻量级框架,主要功能是 IOC(控制反转),DI(依赖注入),AOP(切面编程)。
架构图:
2.IOC底层原理
工厂模式+反射+xml
3.快速入门
#导入核心jar包:
在pom.xml(Maven)中配置核心jar包:
commons-logging,spring-beans,spring-context,spring-core,spring-expression
#入门案例
创建UserService接口,和UserService的实现类UserServiceImp,和测试类SpringDemo1,和applicationContext
UserService:
public interface UserService {
public void sayHello();
}
UserServiceImp:
public class UserServiceImp implements UserService { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public void sayHello() { System.out.println("hello spring"+name); } }
在ApplicationContex.xml中配置:
<bean id="userService" class="com.imooc.ioc.demo1.UserServiceImp"/>
SpringDemo1:
@Test public void demo02(){ ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); UserService service = (UserService) context.getBean("userService"); service.sayHello(); }