The 1th Chapter Spring Introduction

Source: Internet
Author: User

To reduce the complexity of Java development, Spring has adopted the following 4 key strategies:

    • Lightweight and minimal intrusive programming based on POJO;

    • Loose coupling is achieved by dependency injection and interface oriented;

    • Declarative programming based on facets and conventions;

    • Reduce boilerplate code with facets and templates

sping Application Context

Spring comes with several types of application contexts. Here are a few of the most likely ones you'll encounter.

    • Annotationconfigapplicationcontext: Loads the Spring application context from one or more Java-based configuration classes.

    • Annotationconfigwebapplicationcontext: Loads the Spring Web application context from one or more Java-based configuration classes.

    • Classpathxmlapplicationcontext: Loads the context definition from one or more XML configuration files under the classpath, using the definition file of the application context as the class resource.

    • Filesystemxmlapplicationcontext: Loads the context definition from one or more XML configuration files under the file system.

    • Xmlwebapplicationcontext: Loads the context definition from one or more XML configuration files under the Web application.

Bean's life cycle

As you can see, the Bean Factory performs several boot steps before the bean is ready. We have a detailed description of Figure 1.5:

1. Spring initializes the bean to the instance;

2. Spring injects values and bean references into the corresponding attributes of the bean;

3. If the bean implements the Beannameaware interface, Spring passes the Bean's ID to the Setbean-name () method;

4. If the bean implements the Beanfactoryaware interface, Spring calls the Setbeanfactory () method, passing the Beanfactory container instance in;

5. If the bean implements the Applicationcontextaware interface, Spring calls the Setapplicationcontext () method, passing in a reference to the application context where the bean resides; span>

6. If the bean implements the Beanpostprocessor interface, Spring will call their post-processbeforeinitialization () method;

7. If the bean implements the Initializingbean interface, Spring will call their After-propertiesset () method. Similarly, if the bean declares the initialization method using Init-method, the method is also called;

8. If the bean implements the Beanpostprocessor interface, Spring will call their post-processafterinitialization () method;

9. At this point, the beans are ready to be used by the application and will reside in the application context until the application context is destroyed;

10. If the bean implements the Disposablebean interface, Spring will call its destroy () interface method. Similarly, if the bean declares the destroy method using Destroy-method, the method is also called.

Spring Module

Spring Web Flow

Built on the Spring MVC framework, Spring WEB flow provides support for process-based conversational WEB applications that can think of shopping carts or wizard functions. We'll discuss more about spring Web flow in the 8th chapter, and you can also access the spring Web Flow's home page ( http://projects.spring.io/spring-webflow/ ).

Spring Web Service

While the core Spring framework provides the ability to publish the spring bean declaratively as a Web service, these services are built on top of a controversial architecture (poorly contracted post model). The contract for these services is determined by the Bean's interface. Spring Web Service provides a contract-first Web service model, and the implementation of the service is written to meet the contract of the service. This book will no longer explore spring Web service, but you can browse the site http://docs.spring.io/spring-ws/site/to learn more about the Spring Web service.

Spring Security

Security is a very critical facet for many applications. Spring AOP provides a declarative security mechanism for spring applications. You'll see in the 9th Chapter How to add Spring Security functionality to the Web tier of your app. At the same time, we will return to the Spring Security topic in chapter 14th to learn how to protect method invocations. You can get more information about spring security on the main page http://projects.spring.io/spring-security/.

Spring Integration

Many enterprise-class applications need to interact with other applications. Spring integration provides a spring declarative style implementation of a variety of common application integration patterns. We won't cover spring integration content in this book, but if you want to learn more about spring integration, I recommend Mark Fisher, Jonas Partner, Marius Bogoevici and I Spring Integration in Action (Manning, www.manning.com/fisher/) written by Wein Fuld, or you can also access spring Integr Ation's homepage http://projects.spring.io/spring-integration/ .

Spring Batch

When we need to do a lot of work on the data, no technology can be more qualified for this scenario than batch processing. If you need to develop a batch application, you can use spring batch to work with spring's powerful programming model for POJO. Spring Batch is beyond the scope of this book, but you can read the Gregory in Ac written by Arnaud Cogoluegnes, Thierry templier, Gary Olivier, and Bazoud Springbatch tion "(Manning, www.manning.com/templier/ ), or visit the home page of Spring Batch http://projects.spring.io/ spri ng-batch/.

Spring Data

Spring Data makes it easy to use any database in spring. Although relational databases dominate enterprise-level applications for many years, modern applications are realizing that not all data fits into rows and columns in a single table. A new type of database, often referred to as a NoSQL database [2], provides a new way to use data that is more appropriate than a traditional relational database. Whether you use a document database, such as MongoDB, a graph database, such as neo4j, or a traditional relational database, Spring Data provides a simple programming model for persistence. This includes providing an automated Repository mechanism for multiple database types, which is responsible for creating Repository implementations for you. We'll see in the 11th chapter how to use Spring Data to simplify Java persistence API (JPA) development, and then in chapter 12th, expand the discussion to several NoSQL databases.

Spring Social

Social networking is a new trend in the Internet, and more and more applications are being incorporated into social networking sites, such as Facebook or Twitter. If you're interested, you can look at spring social, a social networking extension for spring. However, Spring social is more than just tweets and friends. Although the name is so, Spring social is more about connection (connect) than social (social). It helps you connect to the spring app through the REST API, some of which may not have any social functional goals. Confined to space, we do not involve Spring social in this book. However, if you are interested in how Spring helps you connect to Facebook or Twitter, you can check the URL https://spring.io/guides/gs/accessing-facebook/and the Getting Started guide in https://spring.io/guides/gs/accessing-twitter/.

Spring Mobile

Mobile applications are another compelling area of software development. Smartphones and tablet devices have become the preferred client for many users. Spring Mobile is a new extension module for Spring MVC that supports mobile WEB application development.

Spring for Android

Related to Spring Mobile is the Spring Android project. This new project is designed to provide some simple support for developing native Android device-based applications through the Spring framework. Initially, this project provided a version of Spring resttemplate that could be used in Android apps. It also works with Spring social, allowing native apps to connect to social networks through the rest API. In this book, I won't Talk about Spring for Android, but you can learn more by Http://projects.spring.io/spring-android/.

Spring Boot

Spring greatly simplifies many programming tasks, reduces or even eliminates many boilerplate code, and, without spring, you have to write boilerplate code like this in your daily work. Spring Boot is a new exciting project that is focused on simplifying spring itself in the spring perspective. Spring Boot relies heavily on automatic configuration technology to eliminate most (in many scenarios, even all) spring configurations. It also provides multiple Starter projects, whether you use Maven or Gradle, which reduces the size of the Spring project build file. We will learn Spring Boot in the 21st chapter of the book that is about to end.

The 1th Chapter Spring Introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.