Spring AOP AspectJ Xml Configuration Example

AspectJ libraries provides the facility to declare aspect, pointcut etc using xml file. Let us discuss the syntax first. Declaring an aspect: The element is used to declare an aspect. The ref attribute is used for bean reference. Declaring a pointcut: The element is used to declare an pointcut. The expression element represents the expression … Read more

Spring AOP tutorial

AOP refers to Aspect Oriented Programming which behaves like OOPs as both provides the concept of modularity. But the difference is it uses aspect rather than class for the unit of modularity. Aspect Oriented Programming breaks down program logic into distinct parts called concerns. A cross-cutting concerns are aspects of a program that affect other … Read more

Spring dependency injection collections

Spring framework provides the facility to inject collection values via constructor or setter method. We can use the following inside the constructor or property element. 1. List. 2. Set. 3. Map. Syntax (constructor based dependency injection): <bean id="testBeanId" class="Test"> <constructor-arg> <list> <value>value1</value> <value>value2</value> <value>value3</value> </list> </constructor-arg> </bean><bean id="testBeanId" class="Test"> <constructor-arg> <list> <value>value1</value> <value>value2</value> <value>value3</value> </list> … Read more

Setter based dependency injection

Setter based dependency injection is a process of passing the dependency to a dependent object via a setter method. Note: 1. For primitive data types use element and for dependent objects use <ref bean="beanId"/><ref bean="beanId"/> 2. Index attribute is used to specify the index of constructor arguments. Example Explanation: We have created two beans “Student” … Read more

Constructor injection type ambiguities in spring

In case of constructor based dependency injection if our class contains multiple constructors with different types and same number of arguments then spring framework cause the constructor injection argument type ambiguities issue. Let us discuss it with below example. Example Explanation: We have created one bean class “Student” which have two constructors with same number … Read more

Spring constructor based injection

Constructor based dependency injection is a process of passing the dependency to a dependent object via a constructor. Note: 1. For primitive data types use element and for dependent objects use <ref bean="beanId"/><ref bean="beanId"/> 2. Index attribute is used to specify the index of constructor arguments. Example Explanation: We have created two beans “Student” and … Read more

Spring dependency injection tutorial

Injection: Injection is a process of passing the dependency to a dependent object. Dependency Injection (DI): Dependency Injection (DI) is a design pattern that implements inversion of control principle for resolving dependencies. It allows a programmer to remove hard coded dependencies so that the application becomes loosely coupled and extendable. Let us discuss object dependency … Read more

Spring bean definition template

As we discussed earlier a bean definition in configuration metadata can contain constructor arguments, property values etc. Spring framework provides the facility to define a bean definition template which can be used by child bean definitions. To define a template remove class attribute and use abstract attribute to true in bean definition. Use parent attribute … Read more

Spring bean definition inheritance

As we discussed earlier a bean definition in configuration metadata can contain constructor arguments, property values etc. Spring framework provides the facility that a child bean definition can inherits configuration data from a parent definition. A child definition can override some values of parent definition or add some others, as required. Use parent attribute in … Read more

Spring hello world example in eclipse

Let us create spring hello world example by following below steps: 1. Download spring jar files and add into project class path. Or use the maven, see our Maven Eclipse Spring example. 2. Create java class (bean). 3. Create spring configuration file which contains all bean configurations. 4. Create spring test class. 5. Load spring … Read more