| public class BusinessLogicException extends Exception {} public interface IBusinessLogic { public void foo(); public void bar() throws BusinessLogicException; } public class BusinessLogic implements IBusinessLogic { public void foo() { System.out.println("Inside BusinessLogic.foo()"); } public void bar() throws BusinessLogicException { System.out.println("Inside BusinessLogic.bar()"); throw new BusinessLogicException(); } } |
| import org.springframeworkcontext.ApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext; public class MainApplication { public static void main(String [] args) { // Read the configuration file ApplicationContext ctx = new FileSystemXmlApplicationContext( "springconfig.xml"); //Instantiate an object IBusinessLogic testObject = (IBusinessLogic) ctx.getBean("businesslogicbean"); //Execute the public methods of the bean testObject.foo(); try { testObject.bar(); } catch(BusinessLogicException ble) { System.out.println("Caught BusinessLogicException"); } } } |
| import org.springframework.aop.ThrowsAdvice; import java.lang.reflect.Method; public class LoggingThrowsAdvice implements ThrowsAdvice { public void afterThrowing(Method method, Object[] args, Object target, Throwable subclass) { System.out.println("Logging that a " + subclass + "Exception was thrown."); } } |
聯(lián)系客服