Spring5知识点总结

  • 介绍
    1. 平常说的spring也值spring framework
    2. 核心库:spring core beans context
    3. 现在最新的版本为5.1.9(8月2号)
    4. 核心思想:
      1. spring ioc(inverser of control)控制反转;
      2. DI(Dependency Injection)依赖注入
      3. AOP(Aspected oriented Programming)面向切面编程
  • IOC&DI
    1. IOC基于xml
      1. <bean> 标签有id class scope init-method destory-method
      2. 实现的方法
        1. 无参构造函数<bean id=“userService” class=“com.tmlong.UserSreviceImpl”></bean>
        2. 静态工厂<bean id=“userService” class=“com.tmlong.UserFactory” factory-method=“createUserService"
        3. 实例工厂
    2. DI基于xml
      1. 构造函数 constructor-args:index name ref value
      2. 手动:set方法<bean>子标签 property 自动:@AutoWired @R
      3. esouce
    3. IOC基于注解
      1. @Component 以及衍生 @Service @Controller @Repository(配置文件加上context:component-scans 或者@ComponentScan)
    4. DI基于注解
      1. @AutoWired @Resource @Value
    5. 纯注解进阶
      1. @Configuration 相当于xml的<beans>
      2. @Bean 相当于xml的<bean>
      3. @ComponentScan 相当于xml component-scan
      4. @PropertySource value为配置路径 属性可以直接引用@Value,相当于propery-plcaeholder
      5. @Import 组合多个配置类,相当于xml import 导入其它配置类
      6. 通过注解获取容器
  • AOP
  • Spring整合Junit
    1. 默认情况需要获取容器,通过读取配置文件(ApplicationContext.xml)创建ClassPathXmlApplicationContext(“.xml”)创建,然后获取对象
    2. 在Junit 注解@RunWith,可以指定@RunnerWith(“SpringJunit4ClassRunner.class”),然后通过@ContextConfiguration(“.xml")配置 .xml文件
    發表評論
    所有評論
    還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
    相關文章