Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法使用Spring LoadTimeWeaving将建议应用于第三方库(log4g-Logger.getLogger调用)?_Java_Spring_Aop - Fatal编程技术网

Java 无法使用Spring LoadTimeWeaving将建议应用于第三方库(log4g-Logger.getLogger调用)?

Java 无法使用Spring LoadTimeWeaving将建议应用于第三方库(log4g-Logger.getLogger调用)?,java,spring,aop,Java,Spring,Aop,Hi-am无法使用Spring LoadTimeWeaving向第三方库(log4g-Logger.getLogger调用)应用建议 1。SpringConfig.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml

Hi-am无法使用Spring LoadTimeWeaving向第三方库(log4g-Logger.getLogger调用)应用建议

1。SpringConfig.xml

<?xml version="1.0" encoding="UTF-8"?>
<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:aop="http://www.springframework.org/schema/aop" 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/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

    <!-- Spring Application Context holder that is used by code that can not be injected by spring.
    One example is the log4j appender called LogEventAppender.
     -->
     <!-- <context:property-placeholder location="classpath:/hello_${env}.properties"/> -->

    <context:load-time-weaver/>


    <context:spring-configured/>

    <context:component-scan base-package="com.app.svc">
        <!-- In the case the IFA is in the same class path that this spring context is being loaded from exclude this
        generator from including IPA classes. This happens in the fusion-util module. -->
    </context:component-scan>

    <aop:aspectj-autoproxy/>

</beans>
注意:提供了以下java VM参数<代码>-javaagent:D:\devel\spring\spring-instrument-3.2.3.RELEASE.jar

它没有在控制台上打印任何内容。如果我在我的应用程序中将切入点定义更改为某个包,那么它就可以工作

所以看起来它无法将方面应用于Log4j.xml


请提供任何建议。

正确进行装货时间编织是一件棘手的事情。。。基本上,你的方面是破坏能力加载时间编织。。。您依赖于Log4j,它在应用loadtime编织之前已经加载了Log4j。Loadtime编织只适用于尚未加载到类加载器中的类。我经常发现使用AspectJ的eclipse插件编写代码很有用。它的交叉引用窗口非常方便,可以查看是否应用了方面——可以同时使用注释和“纯”方面。至于你的问题,考虑尝试“呼叫”而不是“执行”。
<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
<aspectj>

    <weaver>
        <!-- only weave classes in our application-specific packages -->
        <include within="com.app.svc.*" />
        <include within="org.apache.log4j.*" />
    </weaver>

    <aspects>
        <!-- weave in just this aspect -->
        <aspect name="com.app.svc.MyLoggingAspect" />
    </aspects>

</aspectj>
package com.app.svc;

import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class MyLoggingAspect {

    @Around("getLoggerPointCut()")
    public Object changeFileAppender(ProceedingJoinPoint pjp) throws Throwable {
        System.err.println("---------------- MyLoggingAspect ##--------------------");
        Object proceed = pjp.proceed();
        return proceed;
    }

    //This is not working - Pointcuts for classes in 3rd party jar. 
    @Pointcut("execution(public org.apache.log4j.Logger org.apache.log4j.Logger.*(..))")
    public void getLoggerPointCut(){}   

    //This works - Pointcuts for classes in application.
    //@Pointcut("execution(public * com.app.svc.NewHello.info(..))")
    //public void getLoggerPointCut(){} 

}