Spring入门

来源:互联网 发布:ubuntu如何卸载samba 编辑:程序博客网 时间:2024/06/10 01:44

1.Spring 起承上启下作用(web和数据层)

2.Spring 的核心:控制反转(Ioc)面向切向(AOP)

3.核心容器:beans、core、context、 expression

4.导jar包:4核心,1依赖

4核心:beans、core、context、expression;1依赖logging

5.配置文件:

  • 位置:任意,开发一般都在classpath下(src)
  • 名称:任意,开发一般都用 applicationContext.xml
  • 内容:添加 schema约束 约束文件位置:spring-framework-3.2.0.RELEASE-dist.zip\spring-framework-3.2.0.RELEASE\docs\spring-framework-reference\html\xsd-config.html
  • 配置service:<bean>配置需要配置的对象;id:为bean命名,唯一;class:bean的全限定类名
  • // 从Spring容器中获得
    //1.获得容器
    String xmlPath="com/xdq/a_ioc/beans.xml";
    ApplicationContext applicationContext=new ClassPathXmlApplicationContext(xmlPath);
    //2.获得内容,不需要new,都是从Spring容器中获取
    UserService userService=(UserService) applicationContext.getBean("userService");
    userService.addUser();

5.DI 依赖注入

is a :是一个,继承

has a :有一个,引用成员变量,依赖

eg;

class A{

private B b;//A类依赖B类

}

依赖:一个类需要使用另一个类


0 0