Skip to main content

Spring’s AOP with Struts

Using Spring’s AOP with your Struts Application:

To tackle cross-cutting you can use Spring interceptors
To use Spring’s AOP in your Struts Applications you need to :

1. Create the interceptor.
2. Registor the interceptor.
3. Delclare interceptors.

For example
A sample logging interceptor
  
package net.champ.example1.employee.interceptors;

import org.springframework.aop.MethodBeforeAdvice;
import java.lang.reflect.Method;

public class LoggingInterceptor implements MethodBeforeAdvice {

public void beforeMethod(Method method, Object[] objects, Object o) throws Throwable {
System.out.println("logging before intersection");
}
}

This interceptor will execute the beforeMethod() before every intersection (We are using MethodBeforeAdvice). Here we are just printing a line but we can use it for anything we like. Next let us register the interceptor.
Registering the interceptor in the Spring config file
  
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
<bean id="empSearchService" class="net.champ.example1.employee.business.EmpSearchServiceImpl">
<bean name="/submitSearch"
class="net.champ.example1.employee.actions.SubmitSearch">
<property name="empSearchService">
<ref bean="empSearchService">
</property>
</bean>

<!-- Interceptors -->
<bean name="logger"
class="net.champ.example1.employee.interceptors.LoggingInterceptor"/>
<!-- AutoProxies -->
<bean name="loggingAutoProxy"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<value>/submitSearch>/values>
</property>
<property name="interceptorNames">
<list>
<value>logger>/value>
</list>
</property>
</bean>

</beans>

Explanation:
First we have to register the interceptor:
 
<bean name="logger"
class="net.champ.example1.employee.interceptors.LoggingInterceptor"/>

Now we need to define the intersections, we will use autoproxy:

<bean name="loggingAutoProxy"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">

Now we have to register the Struts action’s that will be intercepted.

<property name="beanNames">
<value>/submitSearch>/values>
// <value>/otherBeans>/values>
</property>

Apply interceptors to the beanNames:

<property name="interceptorNames">
<list>
<value>logger>/value>
</list>
</property>

Comments

Popular posts from this blog

JSF Lifecycle Phases

JSF Lifecycle Phases JSF follows MVC design pattern to handle request-response process. Basically JSF handles three types of requests. Non-Faces Request Generates Faces Response Faces Request Generates Non-Faces Response Faces Request Generates Faces Response In another case of course non-jsf to non-jsf is there but in this case there is no involvement of JSF action here, so this is not a part of jsf lifecycle process. A JavaServer Faces page is represented by a tree of UI components, called a view . When a client makes a request for the page, the life cycle starts. During the life cycle, the JavaServer Faces implementation must build the view while considering state saved from a previous submission of the page. When the client submits a page, the JavaServer Faces implementation must perform several tasks, such as validating the data input of components in the view and converting input data to types specified on the server side. The JavaServer Faces implementation performs a...

Hibernate Reverse Engineering

Hibernate Revers enginering is the process of creating hibernate mapping files and pojo classes from an exising database tables.It has been explicitly achived by using HIbernate Tools. In Eclipse IDE we have to put the hibernate tool in our eclipse version. In net beans 6.8 it is by defaultly avialable to you. Fid below the handling of the required hibernate tool on different IDE's. Reveres Engineering using Net Beans Ide

Flash Lite Application Set Up

Steps to develop an mobile application on flash lite and deploy the same on some device. Step 1: Download Adobe Flash CS4 from net step 2 : Follow the instructions to execute the Adobe flash set up. After every thing installed successfully, follow the below instructions to develop your first Flash Lite Application Hello Mobile World: Creating Your First Flash Lite Project This section contains step-by-step instructions to walk you through the creation of your first Flash Lite Project. This section assumes that you have downloaded and installed Flash CS3 Professional which includes Adobe Device Central. 1.Start Flash CS3 Professional 2.File > New > Flash File (Mobile) 3.Adobe Device Central starts up to allow you to choose the main target device 4.In the 'Device Sets' panel choose 'Flash Lite 2.1 32 240x320'. This is the generic mobile device profile provided by Adobe for a Flash Lite 2.1 device. 5.Click the 'Create' button at the bottom right of Device Ce...