concept spring in category spring

appears as: Spring, Spring
Spring Microservices in Action, 2E

This is an excerpt from Manning's book Spring Microservices in Action, 2E.

1.2      Microservices with Spring

Spring has become the de facto development framework for building Java-based applications. At its core, Spring is based on the concept of dependency injection. In a typical Java application, the app is decomposed into classes where each class often has explicit linkages to other classes in the application. The linkages are the invocation of a class constructor directly in the code. Once the code is compiled, these linkage points can’t be changed.

This is problematic in a large project because these external linkages are brittle and making a change can result in multiple downstream impacts to other code. A dependency injection framework, such as Spring, allows you to more efficiently manage large Java projects by externalizing the relationship between objects within your application through convention (and annotations) rather than those objects having hard-coded knowledge about each other. Spring sits as an intermediary between the different Java classes of your application and manages their dependencies. Spring essentially lets you assemble your code like a set of Lego bricks that snap together.

Spring in Action, Sixth Edition

This is an excerpt from Manning's book Spring in Action, Sixth Edition.

As software development evolved, the Spring Framework also changed to address modern development concerns, including microservices and reactive programming. Spring also set out to simplify its own development model by introducing Spring Boot.

Whether you’re developing a simple database-backed web application or constructing a modern application built around microservices, Spring is the framework that will help you achieve your goals. This chapter is your first step in a journey through modern application development with Spring.

Spring Microservices in Action

This is an excerpt from Manning's book Spring Microservices in Action.

Spring has become the de facto development framework for building Java-based applications. At its core, Spring is based on the concept of dependency injection. In a normal Java application, the application is decomposed into classes where each class often has explicit linkages to other classes in the application. The linkages are the invocation of a class constructor directly in the code. Once the code is compiled, these linkage points can’t be changed.

This is problematic in a large project because these external linkages are brittle and making a change can result in multiple downstream impacts to other code. A dependency injection framework, such as Spring, allows you to more easily manage large Java projects by externalizing the relationship between objects within your application through convention (and annotations) rather than those objects having hard-coded knowledge about each other. Spring sits as an intermediary between the different Java classes of your application and manages their dependencies. Spring essentially lets you assemble your code together like a set of Lego bricks that snap together.

Spring Boot in Action

This is an excerpt from Manning's book Spring Boot in Action.

Perhaps the most exciting, most head-turning, most game-changing new thing to come to Spring in the past year or so is Spring Boot. Spring Boot offers a new paradigm for developing Spring applications with minimal friction. With Spring Boot, you’ll be able to develop Spring applications with more agility and be able to focus on addressing your application’s functionality needs with minimal (or possibly no) thought of configuring Spring itself. In fact, one of the main things that Spring Boot does is to get Spring out of your way so you can get stuff done.

1.1. Spring rebooted

Spring started as a lightweight alternative to Java Enterprise Edition (JEE, or J2EE as it was known at the time). Rather than develop components as heavyweight Enterprise JavaBeans (EJBs), Spring offered a simpler approach to enterprise Java development, utilizing dependency injection and aspect-oriented programming to achieve the capabilities of EJB with plain old Java objects (POJOs).

Listing 4.1. Integration testing Spring with SpringJUnit4ClassRunner
Spring in Practice

This is an excerpt from Manning's book Spring in Practice.

The JDBC API is a useful and well-known approach to accessing data in a relational database. But it can be somewhat cumbersome to use, because it involves a lot of boilerplate code that acquires connections, creates statements, executes queries, and then closes all those things in the reverse order. This recipe shows how Spring simplifies JDBC-based data access.

Spring makes liberal use of the template pattern, and because it’s a perfect fit for circuit breakers, you’ll use it too. But first you’ll do a little framework setup code. In this chapter all we’re worried about is circuit breakers, but we want to make it easy to expand this to other similar components. We call such components guards because they guard integration points.[2] So you’ll start by defining a simple interface for guards generally.

Spring 2 introduced custom namespaces, which essentially allow you to accomplish configuration tasks without having to know exactly which beans are required behind the scenes. Each custom namespace defines a domain-specific language (DSL) that simplifies configuration. Moreover, the custom namespace tags hide the details of what’s going on, such as the fact that multiple beans were created, or that various postprocessors were created, and so forth. This can make configuration easier.

Spring Integration in Action

This is an excerpt from Manning's book Spring Integration in Action.

The main idea behind IoC and the Spring Framework itself is that code should be as simple as possible while still supporting all of the complex requirements of enterprise applications. In other words, those complexities can’t be wholly ignored but ideally shouldn’t have a negative impact on developer productivity or software quality. To accomplish that goal, the responsibility of controlling those complexities should be inverted from the application code to a framework. The bottom line is that enterprise development isn’t easy, but it can be much easier when a framework handles much of the difficult work. With that as our definition, we discuss two key techniques that invert control when using Spring: dependency injection and method invocation. We also briefly explain the role of each technique in the Spring Integration framework.

The logical starting point for any discussion of the Spring Framework’s JMS support is the JmsTemplate. This is a convenience class for interacting with the JMS API at a high level. Those familiar with Spring are probably already aware of other templates, such as the JdbcTemplate and the TransactionTemplate. These components are all realizations of the Template pattern described in the Gang of Four’s Design Patterns: Elements of Reusable Object-Oriented Software (Gamma et al., Addison-Wesley, 1994). Each of these Spring-provided templates satisfies the common goal of simplifying usage of a particular API. One quick example should be sufficient to express this idea. First, we look at code that doesn’t use the JmsTemplate but instead performs all actions directly with the JMS API. Note that even a simple operation such as sending a text-based message involves a considerable amount of boilerplate code. Here’s a simple send-and-receive echo example:

Figure 17.5. Inside the META-INF directory, we see the MANIFEST.MF file which contains the OSGi standard dependency directives. We also see a spring folder. Gemini Blueprint reads the .xml files in this folder and starts a special application context (BundleContext) containing the beans described in these files.
Spring Roo in Action

This is an excerpt from Manning's book Spring Roo in Action.

Spring (and Roo) code is a challenge to show in book format because the names of fully qualified classes often run quite long. We may abbreviate those names because we know that most developers can use an IDE or even Google to look up the packages of well-known classes such as the one above. By the way, it’s LocalContainerEntityManagerFactoryBean, which is located in the org.springframework.orm.jpa package.

Spring Batch in Action

This is an excerpt from Manning's book Spring Batch in Action.

The tasklet is configured as part of the job and consists of two changes in Spring: declare the tasklet as a Spring bean and inject it as a step in the job. To do this, you must modify the configuration you wrote for reading and writing products, as shown in the following listing.

Spring offers support for each integration style. Table 11.2 lists the Spring technologies to use for each integration style.

Configuring the Controller, Repository, and Gateway with Spring

It’s time to configure the components used to receive product import submissions. If you guessed that we use Spring for this configuration, you’re correct. Let’s start by registering the Spring MVC REST controller. This configuration must take place in the file /WEB-INF/sbia-servlet.xml. The following XML snippet shows the configuration of the REST controller:

That’s it! Spring detects the REST controller because you use component scanning and annotate the controller class with @Controller. Spring then wires the controller dependencies. Let’s now see the configuration for the repository and gateway.

Spring Dynamic Modules in Action

This is an excerpt from Manning's book Spring Dynamic Modules in Action.

Singleton and prototype scopes were the only two scopes allowed in Spring 1. Spring 2 introduced new web-based bean scopes. With web-based scopes, beans can be tied to the HTTP request or session and even injected into singleton or prototype beans, with the lightweight container taking care of the wiring.

Listing 7.8. Configuration of the Hibernate JPA implementation with Spring
Dependency Injection: Design Patterns Using Spring and Guice

This is an excerpt from Manning's book Dependency Injection: Design Patterns Using Spring and Guice.

Spring Framework is a groundbreaking and cornerstone dependency injection library of the Java world. It is largely responsible for the popularity and evolution of the DI idiom and for a long time was almost synonymous with dependency injection. Spring was created by Rod Johnson and others and was initially meant to solve specific pains in enterprise projects. It was established as an open source project in 2003 and grew rapidly in scope and adoption. Spring provides a vast set of abstractions, modules, and points of integration for enterprise, open source, and commercial libraries. It consists of much more than dependency injection, though DI is its core competency. It primarily supports setter and constructor injection and has a variety of options for managing objects created by its dependency injector. For example, it provides support for both the AspectJ and AopAlliance AOP paradigms.

Spring adds functionality, features, and abstractions for popular third-party libraries at alarming rates. It is extremely well-documented in terms of published reference books as well as online documentation and continues to enjoy widespread growth and adoption.

2.3.1. XML injection in Spring

Spring’s primary mode of configuration is an XML file. Though Spring offers many alternatives (we saw one with @Autowired), the XML configuration is its most easily identified and common configuration mechanism. Recall our three wonted steps:

Listing 3.24. Injector configuration for Granny and her Apple provider (in Spring)
<beans ...> <bean id="appleProvider" class="AppleProvider"/> <bean id="granny" class="Granny"> <constructor-arg ref="appleProvider"/> </bean> </beans>