zoukankan      html  css  js  c++  java
  • Spring Framework 官方文档学习(一)介绍

     
    Spring框架提供了大概20个模块,分类为:Core Container, Data Access/Integration, Web, AOP (Aspect Oriented Programming)Instrumentation, Messaging, and Test
     
    1、Core Container包含:spring-core, spring-beans, spring-context, spring-context-support, and spring-expression 模块。
    ①spring-core, spring-beans是Spring框架的基础,提供了IoC和DI功能。spring-beans中的BeanFactory是工厂模式的实现。
     
    ②spring-context模块基于spring-core、spring-beans,是一种框架式访问对象的方法,类似JNDI注册方式。
    还添加了国际化支持、事件传播支持、资源加载支持、上下文的创建支持等等。还有JavaEE的部分功能。
    ApplicationContext接口是该模块的核心。
     
    ③spring-context-support模块则提供了集成通用第三方库的支持,将其集成到Spring应用上下文中,如缓存、邮件、计划、模板引擎。
     
    ④spring-expression模块提供了可在运行时查询和操作对象图的表达式语言,很强大。是对JSP中unified EL的扩展。
    支持:设置/获取属性值,属性分配,方法调用,访问数组、集合及索引的内容,逻辑和数字运算符,命名变量,通过名字在Spring IoC容器中获取对象。
     
    2、AOP and Instrumentation包含:
    spring-aop模块提供了AOP编程,允许定义方法拦截器和切入点,以与具体的功能代码解耦合。
    spring-aspects模块集成了AspectJ。
    spring-instrument模块,提供了类工具支持和类加载器实现,用于特定的应用服务器。
    spring-instrument-tomcat模块,包含了对tomcat的代理。
     
    3、Messaging
    Spring Framework 4 包含了spring-messaging模块,带有Spring Integration项目的关键抽象,如Message、MessageChannel、MessageHandler以及其他,以作为基于消息的应用的基础。 
    也提供了一些注解,可以将消息发送到方法中。
     
    4、Data Access/Integration,包含JDBC、ORM、OXM、JMS和Transaction模块。
    spring-jdbc模块,提供了JDBC抽象层,免除了繁杂的JDBC编码和不同数据库开发商错误代码的分析。
    spring-tx模块,允许代码式和声明书事务管理。(需要实现特定接口,支持所有POJO??)
    spring-orm模块,提供了对常见ORM的集成层,常见ORM包括JPA、JDO和Hibernate。通过使用该模块,你既可以使用ORM的功能,也可以使用Spring提供的功能,例如简单的声明式事务管理。
    spring-oxm模块,提供了抽象层,支持Object/XML映射实现 如JAXB、Castor、XMLBeans、JiBX和XStream。
    spring-jms模块,包含了生产和消费消息功能,集成了spring-messaging模块。
     
    5、Web,包含spring-web, spring-webmvc, spring-websocket, and springwebmvc-portlet模块。
    spring-web模块,提供了基本的web功能,如文件上传、使用Servlet Listeners初始化IoC容器、web容器。同样包含了一个HTTP客户端和Spring远程支持的web部分。
    spring-webmvc模块,包含了MVC和REST Web Service实现。
    spring-webmvc-portlet模块,提供了用于Portlet环境的MVC实现,镜像了spring-webmvc模块的功能。
     
    6、Test
    spring-test模块,支持Spring组件的单元测试和集成测试,使用JUnit或者TestUG。提供了Spring ApplicationContext的加载及缓存。还提供了mock对象!
     
    技巧
    通过使用Spring BOM,在 dependencyManagement 导入spring-framework-bom ,然后就可以保证所有的Spring依赖都是同一个版本 -- 可以不用再声明版本了。
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-framework-bom</artifactId>
                <version>4.3.3.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </dependency>
    <dependencies>
     
    Logging,这是Spring唯一强转要求的外部依赖,JCL。
    关掉JCL:从spring-core模块中排除依赖。或者,选一个依赖取代JCL。
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.3.3.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    至此,已经破坏了应用(不能运行了),所以还需要修复一下。使用JCL的其他实现例如SLF4J。

    SLF4J,是编译时绑定,而不是运行时判断,所以更干净。(应该是指在编译时就判断是否需要相应的代码,不需要就去掉)
    但是,有一些容器内置了JCL的实现,这时单纯的排除依赖是不够的。这时候最好的办法是反转类加载器层次,让应用控制JCL依赖,而非容器控制。(如IBM的WebSphere Application Server。知道就行,略过。)
     
     
    4.0 版本的改进(摘录):
    1. 注入bean时,支持泛型限定。如 @Autowired Repository<Customer> customerRepository  。
    2. CGLIB-based proxy classes 不再需要一个默认构造器。
    3. 新的 @RestController 注解。
    4.1 版本的改进(摘录):
    1. 用Jackson支持JSONP
    2. 新的lifecycle,允许拦截 @ResponseBody@ResponseEntity 方法,在controller返回之后,但写入响应之前。
    3. 新的HttpMessageConverter选项:通过 jackson-dataformat-xml扩展开启基于Jackson的XML序列化支持。如果存在 jackson-dataformat-xml,将取代 JAXB2
    4.2 版本的改进(摘录):
    1. 可以使用Java 8的默认方法来编写配置文件,@Bean 默认方法。
    2. @Import 支持导入常规类作为bean,而不仅仅是配置类了。
    3. 内建的CORs支持,包含全局的(MVC Java config和 XML namespace)和局部的(如@CrossOrigin)配置。
    4. 默认的JSON前缀,由 "{} && " 改成更安全的 ")]}', " 
    4.3 版本的改进(摘录):
    1. Java 8 的默认方法可以用作bean属性的GETTER/SETTER。
    2. 如果目标bean只定义了一个构造方法,就不再需要@Autowired 注解了。
    3. 内建了对 HTTP HEAD and HTTP OPTIONS 的支持。
    4. @RequestMapping 新的组合注解:@GetMapping@PostMapping@PutMapping@DeleteMapping, and @PatchMapping

    5.  

      新的组合注解:@RequestScope, @SessionScope, and @ApplicationScope

    6.  

      新的 @RestControllerAdvice 注解。

    7.  

      新的 @SessionAttribute 和 @RequestAttribute 注解。

    8.  @

      ModelAttribute allows preventing data binding via binding=false attribute (see reference).

    9.  @

      PathVariable may be declared as optional (for use on @ModelAttribute methods).

    10.  

      HTTP消息转换器中一致的charset处理,包括multipart文本内容默认的UTF-8编码。

    11. 静态资源处理使用配置好的ContentNegotiationManager ,来决定媒体类型。

     
     
     
     
     
     
     
     
  • 相关阅读:
    Gitee + PicGo搭建图床 & Typora上传图片到图床
    算法思维 ---- 双指针法
    Floyd's cycle-finding algorithm
    Boyer-Moore Voting Algorithm
    youtube-dl 使用小记
    算法思维 ---- 滑动窗口
    Memo
    英语
    BZOJ 3270
    BZOJ 3196
  • 原文地址:https://www.cnblogs.com/larryzeal/p/5895240.html
Copyright © 2011-2022 走看看