Spring Tutorial Home

  • Managing Database Transactions
  • Remoting in Spring
  • Working with the Web Layer

Spring Home

Java Resources

Community

Site

Example and Steps for Creating Advice-3


Step6:-Create the Class which will call get the object and call the advised method.





package com.visualbuilder.aop;

import org.springframework.beans.factory.BeanFactory;

import org.springframework.context.support.ClassPathXmlApplicationContext;



public final class MainClass {



    public static void main(String[] args) throws Exception {

       

        BeanFactory ctx = new ClassPathXmlApplicationContext("com/visualbuilder/aop/beans.xml");

        Service object = (Service) ctx.getBean("service");

        object.testAdvice();

    }

}



Output:-


The following output will be genertaed on screen when we run the above program.


Sep 19, 2008 12:37:02 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh

INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@133f1d7: display name [org.springframework.context.support.ClassPathXmlApplicationContext@133f1d7]; startup date [Fri Sep 19 12:37:02 IST 2008]; root of context hierarchy

Sep 19, 2008 12:37:02 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions

INFO: Loading XML bean definitions from class path resource [com/visualbuilder/aop/beans.xml]

Sep 19, 2008 12:37:02 PM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory

INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@133f1d7]: org.springframework.beans.factory.support.DefaultListableBeanFactory@2bb514

Sep 19, 2008 12:37:02 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons

INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@2bb514: defining beans [service,advice,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.aop.aspectj.AspectJPointcutAdvisor#0,beforeMethodExecution]; root of factory hierarchy


This is the before method of Advice Class

This is the Test Advice Method

                    

Copyright © 2010 VisualBuilder. All rights reserved