1

我正在尝试用春天做一个小程序

<bean
    id="mybean" 
    class="com.spr.main.Persona"
    p:name="Peter" 
    p:age="33" 
    p:address="LA" 
    p:company="Googel" 
    p:email="Peter@google.com"
/>

<bean id="logger" class="com.spr.main.Log" />

  <aop:config>
    <aop:aspect ref="logger">
        <aop:pointcut id="testPointcut"
                      expression="execution(* com.spr.main.Person.toString(..)) and target (bean)" />
        <aop:before method="logInfo" pointcut-ref="testPointcut" arg-names="bean"/>
        <aop:after-returning method="logWarning" pointcut-ref="testPointcut" arg-names="bean"/>
    </aop:aspect>
</aop:config>

bean 工作正常,但 aop 不显示日志消息,这是 Log 类:

public class Log 
{

public static void logInfo()
{
    Logger.getLogger(Log.class.getName()).log(Level.INFO, "Info Message...");
}

public static void logWarning()
{
    Logger.getLogger(Log.class.getName()).log(Level.WARNING, "Warning Message...");
}
}
4

0 回答 0