无法使用aop实现日志记录

时间:2014-08-11 20:52:53

标签: java spring java-ee aop

我正在尝试在项目中使用aop实现日志记录,但日志未显示在控制台上。以下是我实施的步骤:

步骤1. applicationContext.xml中的更改:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xsi:schemaLocation=
        "http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/util
        http://www.springframework.org/schema/util/spring-util.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/jee
        http://www.springframework.org/schema/jee/spring-jee.xsd">
    <context:annotation-config/>
    <context:property-placeholder location="/WEB-INF/spring/properties/messagingContext.properties"/>  
    <import resource="/spring-jms.xml" />  
    <import resource="/hibernate.xml" />

    <tx:annotation-driven transaction-manager="transactionManager" />    
    <!-- Auto scan the components -->
     <context:component-scan base-package="com.org.myapp" />
    <context:annotation-config />
    <aop:config proxy-target-class="true"/>
    <tx:jta-transaction-manager/>
    <context:annotation-config />   

    <aop:aspectj-autoproxy>
        <aop:include name="myLogger"/>
    </aop:aspectj-autoproxy>

    <bean id="myLogger" 
        class="com.org.myapp.aspect.MyLogger">
    </bean>
</bean>

步骤2.实施方面

@Aspect
public class MyLogger{  
    @Before("execution(public * com.org.myapp.service.TargetClass.targetMethod(..))")
    public void loggingAdvice(){
        System.out.println("Entering into method");
   }
}

现在,当我通过soap请求调用目标类时,该类正在执行而没有任何错误,但是日志未在控制台上打印。

0 个答案:

没有答案