日期:2014-05-19 浏览次数:20809 次
public class MyException extends Exception { static final long serialVersionUID = -7034897190745766939L; public MyException() { super(); } public MyException(String message) { super(message); } public MyException(String message, Throwable cause) { super(message, cause); } public MyException(Throwable cause) { super(cause); } }
@Aspect @Component public class CheckSecurity { @Pointcut("execution(* add*(..))") private void chkAdd() {}; @Before("chkAdd()") public void check() throws Exception { //throw new RuntimeException("出错退出"); throw new MyException("出错退出"); } }
@Component public class UserDao { public void addUser(String name) { System.out.println("addUser"); } }
public class ChkTest { public static void main(String[] args) { ApplicationContext factory = new ClassPathXmlApplicationContext("check.xml"); UserDao dao = (UserDao)factory.getBean("userDao"); try{ dao.addUser(""); } catch(Exception e) { System.out.println(e.getMessage()); } } }