Spring---->projects----->Spring Framework

1.Spring Framework概述:

    • Spring Framework是spring若干子項目中的一個
    • Spring Framework的主要功能有:
        • 依賴注入(dependency injection/IoC),
        • AOP以及聲明式的事務管理機制(Aspect-Oriented Programming including Spring's declarative【聲明式的】 transaction management
        • web applications:Spring MVC web application and RESTful web service framework
        • data access:Foundational support for JDBC, JPA, JMS
        • messaging,
        • testing and more. 
    • Spring的全部功能模塊(about 20 modules):
        • 概述,The Spring Framework總共包含大體20個模塊(modules),每一個模塊都是Spring框架這個project下的子project,也就是說每一個子module都有惟一的artifactId,項目管理工具(maven/gradle)能夠經過引入某個module的artifactId來向開發者的project中引入單獨的某個module。換句話說就是,spring framework下的20個模塊都是獨立的,開發者在使用spring framework的時候徹底能夠根據本身項目的實際須要選擇向本身的project引入spring framework的20個模塊中的任意一個或幾個module,而不是將全部module都引入到你的project中(e.g. so for example if you don’t want to write a web application you don’t need the spring-web modules. )
        • Figure 2.1. Overview of the Spring Framework。The Spring Framework的20個模塊能夠被分紅以下幾類:Core Container, Data Access/Integration, Web, AOP (Aspect Oriented Programming), Instrumentation【儀器儀表】, Messaging, and Test類, as shown in the following diagram.html

          spring overview
        • Table:Spring framework的20個modules的artifactId,有了artifactId,就可使用項目管理工具(如maven/gradle等)來進行dependencies management了。這些module是相互獨立的,能夠任意引入其中的一個或多個module。java

            • spring framework的這20個module都會被髮布到maven中央倉庫,而且Many of the common libraries that Spring depends on also are available from Maven Central,因此可使用maven來進行這些module的dependencies management。使用maven進行dependency management,只須要配置pom.xml,maven就會自動從maven 中央倉庫幫你下載相應的jar包到maven本地倉庫,你的項目就能夠從maven本地倉庫找到它的dependencies並使用它們。maven的引入省去了手動下載、添加項目依賴的jar包的過程。
            • the Maven groupId is  org.springframework.
            • Table 2.1. Spring Framework Artifacts(Spring framework的20個module的artifactId)
              GroupId ArtifactId Description

              org.springframeworkweb

              spring-aopspring

              Proxy-based AOP support數據庫

              org.springframeworkexpress

              spring-aspectsbootstrap

              AspectJ based aspectsapi

              org.springframeworktomcat

              spring-beanswebsocket

              Beans support, including Groovy

              org.springframework

              spring-context

              Application context runtime, including scheduling and remoting abstractions

              org.springframework

              spring-context-support

              Support classes for integrating common third-party libraries into a Spring application context

              org.springframework

              spring-core

              Core utilities, used by many other Spring modules

              org.springframework

              spring-expression

              Spring Expression Language (SpEL)

              org.springframework

              spring-instrument

              Instrumentation agent for JVM bootstrapping

              org.springframework

              spring-instrument-tomcat

              Instrumentation agent for Tomcat

              org.springframework

              spring-jdbc

              JDBC support package, including DataSource setup and JDBC access support

              org.springframework

              spring-jms

              JMS support package, including helper classes to send and receive JMS messages

              org.springframework

              spring-messaging

              Support for messaging architectures and protocols

              org.springframework

              spring-orm

              Object/Relational Mapping, including JPA and Hibernate support

              org.springframework

              spring-oxm

              Object/XML Mapping

              org.springframework

              spring-test

              Support for unit testing and integration testing Spring components

              org.springframework

              spring-tx

              Transaction infrastructure, including DAO support and JCA integration

              org.springframework

              spring-web

              Web support packages, including client and web remoting

              org.springframework

              spring-webmvc

              REST Web Services and model-view-controller implementation for web applications

              org.springframework

              spring-webmvc-portlet

              MVC implementation to be used in a Portlet environment

              org.springframework

              spring-websocket

              WebSocket and SockJS implementations, including STOMP support

        • the Spring Framework的20個module,每一個module的功能(詳述)
            • Core Container(IoC Container)參考資料:

                • 參考資料:
                  1.   Spring官網:IoC Container
                  2.   Spring官網:
                • Core Container包括20個module中的5個模塊,分別是 spring-corespring-beansspring-contextspring-context-support, and spring-expression 這五個module
                • 其中,The spring-core ,spring-context and spring-beans modules 提供IoC功能和依賴注入功能,是the spring framework的基本功能模塊,要想使用spring framework的beanfactory(其實是一個配置文件*.xml或者註解)來管理beans,就必需要引入20個module中的 The spring-core and spring-beans modules 。
                    • The org.springframework.beans and org.springframework.context packages are the basis for Spring Framework’s IoC container. 這些包中最主要的兩個API是The BeanFactory interface以及 ApplicationContext  interface,這兩個接口都是用來管理beans的,建議使用 the ApplicationContext接口。
                    • The BeanFactory interface provides an advanced configuration mechanism capable of managing any type of object.
                    • org.springframework.context.ApplicationContext is a sub-interface of BeanFactory. It adds easier integration with Spring’s AOP features; message resource handling (for use in internationalization), event publication; and application-layer specific contexts such as the WebApplicationContext for use in web applications. 
                    • In short, the BeanFactory provides the configuration framework and basic functionality, and the ApplicationContext adds more enterprise-specific functionality.TheApplicationContext is a complete superset of the BeanFactory,  the ApplicationContext includes all functionality of the BeanFactory,因此通常狀況下咱們會使用 ApplicationContext interface,下面這個網址有使用ApplicationContext接口及其實現類管理beans的教程。固然,你也可使用beanFactory來管理你的beans,以下網址是使用BeanFactory接口管理beans的教程。(Spring官網建議使用the ApplicationContext)
                • the spring-context module
                  • 依賴於the  spring-core and spring-beans 模塊,
                  • 功能:support for internationalization【國際化】 (using, for example, resource bundles), event propagation【傳播】, resource loading, and the transparent【透明的】 creation of contexts by, for example, a Servlet container. The Context module also supports Java EE features such as EJB, JMX, and basic remoting.
                  • 該模塊最經常使用的API:The ApplicationContext interface is the focal point of the Context module. 
                • spring-context-support moduleprovides support for integrating common third-party libraries into a Spring application context for caching (EhCache, Guava, JCache), mailing (JavaMail), scheduling (CommonJ, Quartz) and template engines (FreeMarker, JasperReports, Velocity).
                • The spring-expression module provides是JSP2.1規範中的表達式語言的一個擴展,你可使用表達式語言來setting and getting property values, property assignment, method invocation, accessing the content of arrays, collections and indexers, logical and arithmetic operators, named variables, and retrieval of objects by name from Spring’s IoC container. It also supports list projection and selection as well as common list aggregations.
            • AOP and Instrumentation

                • The spring-aop module提供AOP功能,
                • The separate spring-aspects module provides integration with AspectJ【AspectJ:一個使用java語言編寫的面向切面的框架】.    
                • The spring-instrument module provides class instrumentation support and classloader implementations to be used in certain application servers.
                • The spring-instrument-tomcat module contains Spring’s instrumentation agent for Tomcat.
            • Messaging

                • Spring Framework 4 includes a spring-messaging module to serve as a foundation for messaging-based applications. The module also includes a set of annotations for mapping messages to methods, similar to the Spring MVC annotation based programming model.    
            • Data Access/Integration

                • The spring-jdbc module provides a JDBC-abstraction【抽象】 layer that removes the need to do tedious 【單調乏味的】JDBC coding and parsing【解析】 of database-vendor【數據庫供應商】 specific error codes.

                • The spring-tx module supports programmatic and declarative transaction management for classes that implement special interfaces and for all your POJOs (Plain Old Java Objects).

                  The spring-orm module provides integration layers for popular object-relational mapping APIs, including JPAJDO, and Hibernate. Using the spring-orm module you can use all of these O/R-mapping frameworks in combination with all of the other features Spring offers, such as the simple declarative transaction management feature mentioned previously.

                  The spring-oxm module provides an abstraction layer that supports Object/XML mapping implementations such as JAXB, Castor, XMLBeans, JiBX and XStream.

                  The spring-jms module (Java Messaging Service) contains features for producing and consuming messages. Since Spring Framework 4.1, it provides integration with the spring-messaging module.

                      
            • Web

                • The Web layer consists of the spring-webspring-webmvcspring-websocket, and spring-webmvc-portlet modules.
                • The spring-web module provides basic web-oriented integration features such as多文件上傳功能、初始化IoC 容器等功能(使用Servlet listeners以及面向web的application context來實現這些功能)。 It also contains an HTTP client and the web-related parts of Spring’s remoting support.
                • The spring-webmvc module (also known as the Web-Servlet module) 實現了MVC架構模式以及REST Web Services. Spring’s MVC framework provides a clean separation between domain model code and web forms and integrates with all of the other features of the Spring Framework.

                •  

                  The spring-webmvc-portlet module (also known as the Web-Portlet module) provides the MVC implementation to be used in a Portlet environment and mirrors the functionality of the spring-webmvc module.

                •     
            • Test

                • The spring-test module supports the unit testing and integration testing of Spring components with JUnit or TestNG. It provides consistent loading of SpringApplicationContexts and caching of those contexts. It also provides mock objects that you can use to test your code in isolation.    

 

2.The Spring Frameork的 使用實例(個人project中引入Spring framework的若干module) 

  2.1 Minimum requirements

        • JDK 6+ for Spring Framework 4.x
        • JDK 5+ for Spring Framework 3.x

       2.2spring framework的20個modules有不一樣的組合方法,另外,Spring framework也能夠和其餘技術進行組合開發

          • Figure 2.2. Typical full-fledged Spring web application

               overview full
            Spring’s  declarative transaction management features make the web application fully transactional, just as it would be if you used EJB container-managed transactions. All your custom business logic can be implemented with simple POJOs and managed by Spring’s IoC container. Additional services include support for sending email and validation that is independent of the web layer, which lets you choose where to execute validation rules. Spring’s ORM support is integrated with JPA, Hibernate and JDO; for example, when using Hibernate, you can continue to use your existing mapping files and standard Hibernate  SessionFactory configuration. Form controllers seamlessly integrate the web-layer with the domain model, removing the need for  ActionForms or other classes that transform HTTP parameters to values for your domain model.
          • Figure 2.3. Spring middle-tier using a third-party web framework

            overview thirdparty web
            Sometimes circumstances do not allow you to completely switch to a different framework. The Spring Framework does  not force you to use everything within it; it is not an all-or-nothing solution. Existing front-ends built with Struts, Tapestry, JSF or other UI frameworks can be integrated with a Spring-based middle-tier, which allows you to use Spring transaction features. You simply need to wire up your business logic using an ApplicationContext and use a WebApplicationContext to integrate your web layer.
          • Figure 2.5. EJBs - Wrapping existing POJOs

            overview ejb

             

            The Spring Framework also provides an access and abstraction layer for Enterprise JavaBeans, enabling you to reuse your existing POJOs and wrap them in stateless session beans for use in scalable, fail-safe web applications that might need declarative security.

                  
相關文章
相關標籤/搜索