concept configuration in category spring

This is an excerpt from Manning's book Spring Microservices in Action, 2E.
Suggested configuration to start quickly with a project (Starters)
Since we started our career as software developers, we have always heard the importance of having the application configuration separated from the code. But what does that mean? In most scenarios, this means not having hard-coded values in the code. Forgetting this principle can make the process of making changes within an application more complicated. Why? Because every time a change to the configuration is made, the application has to be recompiled and/or redeployed. To avoid this, developers need to separate the configuration information from the application code completely. Doing this allows developers to make changes to configuration without going through a recompile process, but also it introduces complexity because now developers have another artifact that needs to be managed and deployed with the application.
Listing 5.1 Maven pom file for the Spring Configuration Server
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.4.RELEASE</version> #A <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.optimagrowth</groupId> <artifactId>configserver</artifactId> <version>0.0.1-SNAPSHOT</version> <name>Configuration Server</name> <description>Configuration Server</description> <properties> <java.version>11</java.version> <spring-cloud.version>Hoxton.SR1</spring-cloud.version> #B </properties> <dependencies> #C <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <dependencyManagement> #D <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>

This is an excerpt from Manning's book Spring Security in Action.
Because the security approach is different depending on the solution we implement, the configuration in Spring Security is also different. In this section, we discuss some examples based on different architectural styles as well as other requirements, how the security approach is affected, and what we should take into consideration. These aspects are linked to all the configurations that we’ll work on in the following chapters with Spring Security.
You might have observed that in the examples I presented, I only use HTTP. In practice, your applications will, however, communicate only over HTTPS. For the examples we discuss, the configurations related to Spring Security aren’t different if we use HTTP or HTTPS. So you can focus on the examples related to Spring Security, I won’t configure HTTPS for the endpoints in the examples of this book. But you can enable HTTPS for any of the endpoints if you wish in the way I present in this sidebar.
We can then alter the configuration using different methods of the HttpSecurity object, as shown in this listing.
Listing 2.7 Using the HttpSecurity parameter to alter the configuration
@Configuration public class ProjectConfig extends WebSecurityConfigurerAdapter { // Omitted code @Override protected void configure(HttpSecurity http) throws Exception { http.httpBasic(); http.authorizeRequests() #A .anyRequest().authenticated(); #A } }

This is an excerpt from Manning's book Spring Microservices in Action.
Configuration management of service— How do you manage the configuration of your microservice so that as it moves between different environments in the cloud you never have to change the core application code or configuration? I cover managing service configuration in chapter 3.
At one point or another, a developer will be forced to separate configuration information from their code. After all, it has been drilled into their heads since school that they shouldn’t hard-code values into the application code. Many developers will use a constants class file in their application to help centralize all their configuration in one place. Application configuration data written directly into the code is often problematic because every time a change to the configuration has to be made the application has to be recompiled and/or redeployed. To avoid this, developers will separate the configuration information from the application code completely. This makes it easy to make changes to configuration without going through a recompile process, but also introduces complexity because you now have another artifact that needs to be managed and deployed with the application.

This is an excerpt from Manning's book Spring Boot in Action.
Automatic configuration— Spring Boot can automatically provide configuration for application functionality common to many Spring applications.
Overriding auto-configuration is a simple matter of explicitly writing the configuration as if auto-configuration didn’t exist. This explicit configuration can take any form that Spring supports, including XML configuration and Groovy-based configuration.
When dealing with application security, you’ll almost certainly want to take full charge of the configuration. But it would be a shame to give up on auto-configuration just to tweak a small detail such as a server port number or a logging level. If you need to set a database URL, wouldn’t it be easier to set a property somewhere than to completely declare a data source bean?

This is an excerpt from Manning's book Spring Integration in Action.
It gets even more interesting and more relevant for our lead-up to Spring Integration when we look at Spring’s support for invoking methods on any Spring-managed object. Sure, the MessageListener interface seems simple enough, but it has a few limitations. First, it requires a dependency on the JMS API. This inhibits testing and also pollutes otherwise pure business logic achieved by relying on the IoC principle. Second, and more severe, it has a void return type. That means you can’t easily send a reply message from the listener method’s implementation. Both of these limitations are eliminated if you instead reference a POJO instance that doesn’t implement MessageListener and add the method attribute to the configuration. For example, let’s assume you want to invoke the following service method:
public class QuoteService { public BigDecimal currentQuote(String tickerSymbol) {...} }The configuration would look like this:
In addition to Hamcrest matchers, Spring Integration tests can make use of Mockito extensions. Mocking services out of tests relating to the message flow through the system becomes more important as a system becomes more complex or when service implementations are developed on a different schedule than the configuration that makes up the message bus. This chapter discusses different use cases for the test module. The authors strongly believe that tests shouldn’t hide complexity, so, as mentioned, we include no “Under the hood” section. Instead, you’ll find all the details right with the usage examples.
We can’t overemphasize that changing the application to improve testability is a good thing. In Spring Integration applications, you usually see good decoupled code that’s easy to test. But what about the configuration? With all that XML containing all those little SpEL expressions and intricate dependencies, you could easily get lost.
It’s said that programming in XML is a bad thing (which it is). That’s why Spring Integration focuses on XML as a domain-specific language for the configuration of enterprise integration patterns. It doesn’t include logical constructs such as <if> or <when> in that domain-specific language. Nevertheless, it is arguably possible to cross the fuzzy line into XML programming if the configuration becomes too convoluted. This section offers some pointers to help you spot problems in this area and combat them with your test goggles on.

This is an excerpt from Manning's book Spring Roo in Action.
By the end of this chapter, you’ll see how Roo helps you get rid of much of the tedium Java EE application development demands. You’ll see that you can gain much of the productivity available in dynamic-language, convention-over-configuration platforms such as Ruby on Rails and Grails. This all comes without sacrificing the benefits of Java compile-time type safety, compiled code, and debuggability.
Spring makes those tasks easier and shifts some of them to configuration, rather than coding, such as these:

This is an excerpt from Manning's book Spring Batch in Action.
You’re done with the configuration: the job and infrastructure are ready, and part of the configuration can come from job parameters, which are set when you launch the job. It’s time to write the test for your batch process.
After describing Spring Batch XML capabilities, we show how to configure batch jobs and related entities with this dedicated XML vocabulary. We also look at configuring a repository for batch execution metadata. In the last part of this chapter, we focus on advanced configuration topics and describe how to make configuration easier.

This is an excerpt from Manning's book Spring Dynamic Modules in Action.
Besides its lightweight container and AOP features, the Spring Framework provides support for a number of Java and Java EE standards and frameworks. Although these libraries are self-sufficient, configuring and combining them in an application can turn out to be tricky, largely due to their configuration subtleties; Spring is able to handle configuration for the most common cases, leaving you with very simple configuration steps to perform. If you’re more comfortable with the target framework or use less conventional features, all the regular configuration settings are still available through Spring configuration.
Spring support is particularly useful in the data access area, with its common abstraction layer for transactions and its template-based approach to persistence. Spring deals with common resource management “plumbing” code and allows for declarative transaction management in various situations ranging from managed environments with JTA (Java Transaction API, the transaction standard in Java) to native database transaction with plain JDBC. Declarative transaction management is made possible through Spring AOP support and can be applied to any kind of component. It has no impact on application code, and switching from one environment to another is a matter of configuration. Application components can focus on their primary task and don’t even know they’re fully transactional.
This chapter covers some very advanced topics and settings of Spring DM and of OSGi, so you shouldn’t feel overwhelmed by its content. The chapter isn’t meant to be read sequentially; instead you should acquaint yourself with the types of configuration hooks Spring DM provides and come back to this chapter for the details when you need to use them.

This is an excerpt from Manning's book Dependency Injection: Design Patterns Using Spring and Guice.
This code is simple and readable. The identity of a service (its key) is sufficient to obtain exactly the right service and configuration. Now altering the behavior of a service identified by a particular key or fixing bugs within it by changing its object graph will have no effect on dependent code and can be done transparently.
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:
The file email.xml contains the configuration required for Spring’s injector to provide us with an emailer correctly wired with its dependencies. Listing 2.2 shows what email.xml looks like, and figure 2.8 shows how this works.