Spring Tutorials

Spring Tutorial

Introduction of Spring Framework

Advantages and Disadvantages of Spring Framework

Features of Spring Framework

Basic concept of Spring Framework

Architecture of Spring Framework

Modules of Spring Framework

Goal of Spring Framework

Create Application of Spring without any IDE

Create Application of Spring in Eclipse IDE

Create Application of Spring in MYEclipse IDE

Important JAR of Spring Framework

IOC container in Spring Framework

Bean and Applicationcontext container in Spring Framework

Example of Spring BeanFactory Container in Spring Framework

Example of Spring ApplicationContext Container in Spring Framework

Bean in Spring Framework

Lifecycle of Bean in Spring Framework

Scope of Bean in Spring Framework

Autowiring in Spring Framework

Dependency Injection in Spring Framework

Constructor-based Dependency Injection Example in Spring Framework

Setter-based Dependency Injection Example in Spring Framework

Introduction of AOP in Spring Framework

Core concept and Goal of AOP in Spring Framework

AOP Proxies in Spring framework

XML Schema Based AOP in Spring Framework

AOP Xml based Configuration Example in Spring Framework

Example of Declaring AOP Advices in Spring Framework

AOP AspectJ Annotation with Example in Spring Framework

Declaring an aspect and pointcut using Annotation in Spring Framework

Declaring AOP Advices using Annotation Example in Spring Framework

DAO support in Spring Framework

Introduction of Spring JDBC Framework in Spring Framework

Introduction of Spring JdbcTemplate in Spring Framework

Example of Spring JdbcTemplate class in Spring framework

Example of Executing SQL statements in Spring Framework

Example of Executing DDL statements in Spring Framework

SQL Stored Procedure in Spring Framework

Example of NamedParameterJdbcTemplate in Spring Framework

Example of RowMapperJdbcTemplate in Spring Framework

Introduction of ORM Framework in Spring Framework

Integration of Spring with Hibernate in Spring Framework

Integration of Spring with JPA in Spring Framework

Introduction of Spring Expression Language (SpEL) in Spring Framework

Example of Spring Expression Language (SpEL) in Spring framework

Example of Spring EL in XML and Annotation in Spring Framework

Language Reference with SpEL in Spring Framework

Operators in Spring Expression Language(SpEL) in Spring Framework

Variable in Spring Expression Language(SpEL) in Spring Framework

Introduction of Spring Framework Transaction Management in Spring Framework

Spring Framework Transaction Abstraction

Spring Declarative Transaction Management in Spring Framework

Spring Programmatic Transaction Management in Spring Framework

Introduction of Spring OXM (Object XML Mapping) in Spring Framework

Integration of Spring with Jaxb Example in Spring framework

Example of Spring with Xstream in Spring Framework

Example of Spring with Castor in Spring Framework

Remote Method Invocation(RMI) in Spring Framework

Spring and RMI Integration with Example in Spring Framework

Example of Spring and Httpinvoker in Spring Framework

Example of Spring and Hessian in Spring Framework

Integration of Spring with JMS in Spring Framework

Introduction of Webservice in Spring Framework

Spring Web Services in Spring Framework

Web Services with Jax-WS in Spring framework

Exposing and Exporting servlet-based Web Services using JAX-WS in Spring Framework

Accessing Web Services using JAX-WS in Spring Framework

Introduction of JMS in Spring Framework

JMS Messaging Models in Spring Framework

Using Spring JMS in Spring Framework

Sending and Receiving a Message Using JMS API in Spring Framework

Introduction of JMX (Java Management Extension) in Spring Framework

Integrating Beans with JMX in Spring Framework

Creating a MBeanServer in Spring Framework

Introduction Java Mail with Spring in Spring Framework

Example of Java Mail with spring in Spring Framework

Introduction of EJB(Enterprise JavaBeans) in Spring Framework

Introduction of EJB(Enterprise JavaBeans) Integration in Spring Framework

Integration of Spring With Struts 2 Example in Spring Framework

Spring MVC

Spring MVC

adplus-dvertising
AOP Proxies in Spring framework
Previous Home Next

Spring AOP defaults to using standard JDK dynamic proxies for AOP proxies. This enables any interface (or set of interfaces) to be proxied. Spring AOP can also use CGLIB (Code Generation Library) proxies. This is necessary to proxy classes, rather than interfaces. CGLIB is used by default if a business object does not implement an interface. As it is good practice to program to interfaces rather than classes, business classes normally will implement one or more business interfaces.

It is possible to force the use of CGLIB, in those (hopefully rare) cases where you need to advise a method that is not declared on an interface, or where you need to pass a proxied object to a method as a concrete type.

Mechanism of AOP proxies

Spring AOP is proxy-based. It is vitally important that you grasp the semantics of what that last statement actually means before you write your own aspects or use any of the Spring AOP-based aspects supplied with the Spring Framework. If the target object to be proxied implements at least one interface then a JDK dynamic proxy will be used.

All of the interfaces implemented by the target type will be proxied. If the target object does not implement any interfaces then a CGLIB proxy will be created.

Example

public class Simple implements Pojo {
public void foo() {
//this next method invocation is a direct call on the this reference
this.bar();
}
public void bar() {
// some logic...
}}

If you invoke a method on an object reference, the method is invoked directly on that object reference, as can be seen below.

public class Main {
public static void main(String[] args) {
Pojo pojo = new SimplePojo();
// this is a direct method call on the pojo reference
pojo.foo();
}}

Things change slightly when the reference that client code has is a proxy.

public class Main {
public static void main(String[] args) {
ProxyFactory factory = new ProxyFactory(new SimplePojo());
factory.addInterface(Pojo.class);
factory.addAdvice(new RetryAdvice());
Pojo pojo = (Pojo) factory.getProxy();
// this is a method call on the proxy!
pojo.foo();
}}

Here the client code inside the main(..) of the Main class has a reference to the proxy. This means that method calls on that object reference will be calls on the proxy, and as such the proxy will be able to delegate to all of the interceptors (advice) that are relevant to that particular method call.

AOP Implementations in Spring framework

AOP implementations in Spring are provided the following main task as given below.

  1. Spring AOP
  2. AspectJ
  3. JBoss AOP
Spring AOP

Spring supports the @AspectJ annotation style approach and the schema-based approach to implement custom aspects.

  1. XML Schema based Aspects are implemented using regular classes along with XML based configuration.
  2. @AspectJ based @AspectJ refers to a style of declaring aspects as regular Java classes annotated with Java 5 annotations.
Previous Home Next