12:49 pm - Saturday July 22, 2017

Spring AOP Throws Advice 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:

 

 

 

 

 

 

 

 

 

Jar Files:

 

 

 

 

 

  

 

 

 

 

 

 

 

 

 

How To Add Jar Files:

     

   

 

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("Throwwriter");
		wObj.getName();
		System.out.println();
		try {
			wObj.printThrowException();
		} catch (IllegalArgumentException e) {
			System.out.println(e);
		}
	}

}

Throwable Advice.java:

package com.candidjava;

import org.springframework.aop.ThrowsAdvice;

public class ThrowableAdvice implements ThrowsAdvice {
	public void afterThrowing(IllegalArgumentException e) throws Throwable {
		System.out.println("ThrowException : Throwable method!");
	}
}

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);
	}

	public void printThrowException() {
		throw new IllegalArgumentException();
	}
}

OUTPUT:

DOWNLOAD+SOURCECODE+JARFILES

Filed in: Z-A All Java Codes

Comments are closed.