How to use Spring Factory Method to create Spring Bean

Spring Framework provides Spring Factory Method mechanics to create Beans from static(non-static) method of a Factory Class in XML config files. In the tutorial, JavaSampleApproach will introduce Spring Factory Method with sample codes.

Related Posts:
How to inject Collection in Spring
Inject Properties from Properties File using Spring Environment

[Continue reading…] “How to use Spring Factory Method to create Spring Bean”

Spring Bean Scope Annotation: @RequestScope | @SessionScope | @ApplicationScope

Spring Framework new release 4.3 make some Web Improvements. Among that, it simplifies way to implement Bean Scopes (Request, Session and Application scopes) using Annotation: @RequestScope | @SessionScope | @ApplicationScope. They are only valid in the context of a web-aware Application.

Related Articles:
Spring Bean Scope – Singleton and Prototype
Spring Bean Scope using Annotation – Singleton, Prototype, Request, Session, Global Session, Application

[Continue reading…] “Spring Bean Scope Annotation: @RequestScope | @SessionScope | @ApplicationScope”

Spring Expression Language SpEL

Spring Expression Language (SpEL) is a powerful expression language that supports querying and manipulating an object graph at runtime.

This tutorial shows various examples of ways to use SpEL expressions with XML and annotation based configuration. We also know how to evaluate an expression using SpEL classes and interfaces.

[Continue reading…] “Spring Expression Language SpEL”

@Resource Annotation in Spring

@Resource Annotation is used to indicate a reference to a resource, it is considered an alternative to @Autowired which is an Spring standard. Similar to Java EE 5, we can use @Resource Annotation with field injection or setter method.

This tutorial will cover those kinds of injection which will be used for matching by Name, Type or Qualifier.

[Continue reading…] “@Resource Annotation in Spring”

Spring ThreadPoolTaskExecutor with Callable interface for concurrency programming

Callable is a Java interface that is an useful methodology for control multi-threading returns on concurrency development.

The tutorial will guide you to build a concurrency program with ThreadPoolTaskExecutor of Spring Framework and Callable interface.

[Continue reading…] “Spring ThreadPoolTaskExecutor with Callable interface for concurrency programming”

Spring Profiles – @Profile Annotation and XML Configuration

In application development, sometimes we should make different configuration for each environment. Spring Profiles provides a way to separate application configuration into some parts and they are only available in one or more specific environments.

This tutorial introduces ways to use Spring Profiles by @Profile Annotation or XML Configuration.

[Continue reading…] “Spring Profiles – @Profile Annotation and XML Configuration”

Inject Properties using @Value Annotations vs Environment vs @ConfigurationProperties

@Value Annotations vs Environment vs @ConfigurationProperties.

Spring provides some ways to inject properties from properties file. We have learned how to use them in 3 articles:
@Value Annotation
Environment
@ConfigurationProperties

This tutorial helps you have a comparison view covering those solutions.

[Continue reading…] “Inject Properties using @Value Annotations vs Environment vs @ConfigurationProperties”

Inject Properties from Properties File using Spring Environment

We can load properties value from Properties file to Spring Environment just by using @PropertySource annotation. This tutorial shows you the simple way to get them from Environment object.

Related Articles:
Inject Properties from Properties File using @Value annotation
Inject Properties from Properties File using @ConfigurationProperties Annotation
How to use Spring Factory Method to create Spring Bean

[Continue reading…] “Inject Properties from Properties File using Spring Environment”

Inject Properties from Properties File using @ConfigurationProperties Annotation

This tutorial will show you the better way to handle properties using @ConfigurationProperties Annotation.

In previous article, we have learned about using @Value annotation to inject properties from properties file. This approach has disadvantage that if we wanna change any property, we have to update all files which referenced it.

[Continue reading…] “Inject Properties from Properties File using @ConfigurationProperties Annotation”

Inject Properties from Properties File using @Value Annotation

This tutorial shows you the way to inject Properties from Properties File using @Value Annotation with Java Configuration and @PropertySource.

You will also know how to use SourcesPlaceHolder and ConversionService for specific cases including: List/Arrays, special types (DateTime, Pattern), when a value that should be treated as null or a placeholder fails to resolve.

[Continue reading…] “Inject Properties from Properties File using @Value Annotation”

Difference between annotation-config and component-scan

annotation-config and component-scan are important basic concepts of Spring Core.
This tutorial helps you understand how to use them and difference between them.

[Continue reading…] “Difference between annotation-config and component-scan”

Spring Based Configuration – Java Annotation

Spring based configuration using Annotation help you to create Spring configurations without XML.
This tutorial give you an example with most of Spring Annotation for configuration: @Configuration, @Bean (with custom bean lifecycle method), @Import, @Scope. And they’re in multi-configuration context.

[Continue reading…] “Spring Based Configuration – Java Annotation”

Spring IoC Container

At the Core of Spring Framework, Spring IoC (Inversion of Control) is implemented using the Dependency Injection design pattern. The Spring IoC Container creates, configures and connects the objects (which are called Beans), then manage their life cycle.

This tutorial introduce principle of Spring IoC and a simple example using Containers to you.

[Continue reading…] “Spring IoC Container”

Spring Bean Post Processors

The BeanPostProcessor interface helps us provide our own methods before the initialization of beans and likewise after the initialization of the bean.

BeanPostProcessor are common for all beans in the container where it is defined, so it is different from @PostConstruct, InitializingBean and custom init method which are defined on the bean itself.

Related Article: Spring Bean Life Cycle

[Continue reading…] “Spring Bean Post Processors”

Spring Bean Life Cycle – Callback Interface, Custom Method, Annotation, Aware Interface

Spring Bean Life Cycle is very important because in many applications, we want to create some operations before initializing a Bean or make some operations before bean’s destruction.

This tutorial introduce four ways to control life cycle events of a Bean.

[Continue reading…] “Spring Bean Life Cycle – Callback Interface, Custom Method, Annotation, Aware Interface”

Spring Bean Scope using Annotation – Singleton, Prototype, Request, Session, Global Session, Application

The tutorial shows you the way to implement Bean Scopes (Singleton, Prototype, Request and Session) using Annotation @Scope. Except Singleton and Prototype Scope, the others are only valid in the context of a web-aware Application.

Related Article: Spring Bean Scope – Singleton and Prototype

[Continue reading…] “Spring Bean Scope using Annotation – Singleton, Prototype, Request, Session, Global Session, Application”

Spring Bean Scopes – Singleton and Prototype

Spring Bean Scopes helps you control the scope of the objects which are created from bean definition. This approach is wonderful because you can choose the scope by configuring bean instead of working at Java class level.

The Spring Framework supports 7 scopes, but this tutorial introduces you 2 of them: singleton scope and prototype scope. The others will be discussed in next article.

[Continue reading…] “Spring Bean Scopes – Singleton and Prototype”

How to inject Collection in Spring

Spring supports us the way to inject Collection with type: List, Set, Map and Properties. So we can pass a bundle of direct data values or reference of beans to Collection Objects.

The tutorial shows you how to use XML configuration to do those things.

Related Post:
How to use Spring Factory Method to create Spring Bean

[Continue reading…] “How to inject Collection in Spring”

Spring Bean Definition Inheritance | Spring Boot

Bean Definition Inheritance is a good solution for defining new bean which inherited certain bean conveniently.

We will learn how to use XML configuration to create Inheritance from Bean with parent or abstract template.

[Continue reading…] “Spring Bean Definition Inheritance | Spring Boot”