我采用aop来实现日志集中处理,因此配置了如下代码 <bean id ="exceptionLog" class="com.spring.exception.ExceptionLog"/> 
<bean id="exceptionHandlereAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor"> 
<property name="advice"> 
<ref bean="exceptionLog"/> 
</property> 
<property name="patterns"> 
<value>.*.* </value> 
</property> 
</bean> 
我采用这样的方法实现异常集中管理,却发现,即使出现了异常,日志也没有记录下来,请问怎么回事哦?
我的异常类是
package com.spring.exception;
import java.lang.reflect.Method;import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.springframework.aop.ThrowsAdvice;
public class ExceptionLog implements ThrowsAdvice{
private Logger logger= Logger.getLogger(this.getClass().getName());
public void afterThrowing(Method method,Object[] args,Object target,Throwable subclass)throws Throwable{
logger.log(Level.INFO, args[0] +"执行" +method.getName()+"时有异常抛出......" + subclass);
}
}

解决方案 »

  1.   

    你在log4j的配置文件中配置了吗??
      

  2.   

    我的日志级别是info,而且如果不配这些,是可以输出日志信息的,我的感觉可能是我aop配置有问题的,我通过断点跟踪
    package com.spring.exception; 
    import java.lang.reflect.Method; import org.apache.log4j.Level; 
    import org.apache.log4j.Logger; 
    import org.springframework.aop.ThrowsAdvice; 
    public class ExceptionLog implements ThrowsAdvice{ 
    private Logger logger= Logger.getLogger(this.getClass().getName()); 
    public void afterThrowing(Method method,Object[] args,Object target,Throwable subclass)throws Throwable{ 
    logger.log(Level.INFO, args[0] +"执行" +method.getName()+"时有异常抛出......" + subclass); 


    这段代码,我故意,让程序抛出异常,发现,程序没找到这里来,我想,应该这段配置根本没起到作用吧