11:58 am - Wednesday January 18, 2017

Spring AOP After Returning Example Program in Eclipse

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

Project Structure:

 

 

 

 

 

 

 

 

JarFiles:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

How To Add Jar Files:

       

    

   AfterAdvice.java: 

package com.candidjava;

import java.lang.reflect.Method;

import org.springframework.aop.AfterReturningAdvice;

public class AfterAdvice implements AfterReturningAdvice {

	@Override
	public void afterReturning(Object returnValue, Method method,
			Object[] args, Object target) throws Throwable {
		System.out.println("After ReturningMethod");

	}

}

Main.java:

package com.candidjava;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class Main {

	public static void main(String[] args) {

		ApplicationContext appObj = new FileSystemXmlApplicationContext(
				"Config\\beans.xml");
		Writer wObj = (Writer) appObj.getBean("AfterWriter");
		wObj.getName();
		System.out.println();
	}

}

Writer.java:

package com.candidjava;

public class Writer {

	private String name;

	public void setName(String name) {
		this.name = name;
	}

	public void getName() {

		System.out.println(" This is " + this.name);
	}
}

Beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>

	<bean id="writer" class="com.candidjava.Writer">

		<property name="name" value="Deepa" />

	</bean>

	<bean id="HelloAdvice" class="com.candidjava.AfterAdvice">
	</bean>

	<bean id="AfterWriter" class="org.springframework.aop.framework.ProxyFactoryBean">
		<property name="interceptorNames">
			<list>
				<value>HelloAdvice</value>
			</list>
		</property>

		<property name="target" ref="writer" />

	</bean>

</beans>

OUTPUT:

DOWNLOAD+SOURCECODE+JARFILES


							
							
			
Filed in: Z-A All Java Codes

Comments are closed.