MCQs Test!! VB Basic Test !! Essentials of VB !! Creating User Services !! function !! Anatomy !! GK March-2019 !! DATA TYPES IN JAVA !! Classes ,Constructor ,Methods,Inheritance !! Ecology-I !! Biology 2019 !! Gk april 2019 !! Biology (living world) !! Plant anatomy !! CELL STRUCTURES AND FUNCTION !! General biology !! Human physiology !! Data structure !! Ecology-II !! GK TEST !! Reproduction in plants !! Human reproduction !! The ABC of C !! Operating system set1 !! Operating system set2 !! Gk and current affairs !! Animal kingdom !! Number system !! Animal kingdom-II !! Gk TEST-III !! Number series !! Microorganisms !! Interview question in c !! Time and Work !! Percentage !! General history !! Average !! Cells !! Locomotion and Movement !! paging !! Bacteriology !! Page replacement policy !! Secondary memory and Disk scheduling !! Introduction of Nervous System and neurons !! Plant harmones !! Transport and Mineral Nutrition in Plants !! Neurotransmitters !! Modern Indian History !! Photosynthesis in Plants !! Modern Indian History-II !! Plant respiration !! Environment & Biodiversity !! Environment & Biodiversity - II !! Algae, Bryophytes, Pteridophytes !! Area !! Cricket !! Days of the Year (India and the World) !! Plant Pathology - I !! Indian Transport System !! Plant Pathology - II !! Aptitude !! Biology !! Botany !! C language !! Computer Science !! Core Java !! Gate !! GK !! Mysql !! Operating system !! Physics !! VB-Visual Basic !! Zoology

Spring Framework

Spring Projects

Spring Project 1

Example of Around Advice
Previous Home Next

Introduction: An around advice are used when some operations are to be performed before and after method call and controlled over the return value of the method is to be gain.

Technology use to run this source code

  1. Spring 2.5 jar files
  2. Eclipse IDE
  3. Tomcat Server

Source Code:

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="t" class="org.r4r.One"/>
<bean id="a1" class="org.r4r.AroundAdviser" />
<bean id="proxy" 
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target" ref="t"/>
<property name="interceptorNames">
<list><value>a1</value>
</list>
</property>
</bean>
</beans>

 

Showable.java

package org.r4r;
public interface Showable {
public abstract void show();
}

One.java

package org.r4r;
public class One implements Showable {
@Override
public void show() {
System.out.println("Show() method of One invoked..");
}
}

AroundAdviser.java

package org.r4r;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
public class AroundAdviser implements MethodInterceptor {
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
System.out.println("Before advice is applied...");
Object temp=mi.proceed();
System.out.println
("After advice is applied, "+temp+"\tis return by the method.");
System.out.println
("Returning failure from the advice");
return "failure";
}
}

ProxyTest.java

package org.r4r;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
public class ProxyTest {
public static void main(String[] args) {
Resource r=new ClassPathResource("applicationContext.xml");
BeanFactory f=new XmlBeanFactory(r);
System.out.println("Obtaining proxy of one..");
Showable p=(Showable)f.getBean("proxy");
System.out.println("Proxy obtaining invoked.");
p.show();
}
}

output:

Obtaining proxy of one..
Proxy obtaining invoked.
Before advice is applied...
Show() method of One invoked..
After advice is applied, null is return by the method.
Returning failure from the advice
Previous Home Next