Как я могу настроить свой spring aop xml с помощью aop.xml для ткачества времени загрузки?

У меня есть одно приложение "Hello word" на Spring AOP, настроенное с помощью XML, оно выглядит так:

public class CustomerBoImpl {

    public CustomerBoImpl() {
        super();
    }

    protected void addCustomer(){
        System.out.println("addCustomer() is running ");
    }
}


public class App {
    public static void main(String[] args) throws Exception {
        ApplicationContext appContext =
            new ClassPathXmlApplicationContext("Spring-Customer.xml");

        CustomerBoImpl customer = 
            (CustomerBoImpl) appContext.getBean("customerBo");

        customer.addCustomer();
    }
}

Моя весенняя конфигурация выглядит так:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd ">

<aop:aspectj-autoproxy />
<!-- this switches on the load-time weaving -->
<context:load-time-weaver aspectj-weaving="on" />

<bean id="customerBo" class="com.mkyong.saad.CustomerBoImpl"
    scope="singleton" />

<!-- Aspect -->
<bean id="logAspect" class="com.mkyong.saad.LoggingAspect" />

<aop:config>

    <aop:aspect id="aspectLoggging" ref="logAspect">

        <!-- @Before -->
        <aop:pointcut id="pointCutBefore"
            expression="execution(* com.mkyong.saad.CustomerBoImpl.addCustomer(..))" />

        <aop:before method="logBefore" pointcut-ref="pointCutBefore" /> 

        <!-- @After -->
        <aop:pointcut id="pointCutAfter"
            expression="execution(* com.mkyong.saad.CustomerBoImpl.addCustomer(..))" />
        <aop:after method="logAfter" pointcut-ref="pointCutAfter" />


    </aop:aspect>

</aop:config>

это не работает из-за защищенного метода, поэтому я попытался использовать переплетение времени загрузки с aop.xml следующим образом:

<?xml version="1.0" encoding="UTF-8"?>
<aspectj>
    <weaver>
        <!-- only weave classes in our application-specific packages -->
        <include within="com.mkyong.saad.*"/>
    </weaver>

    <aspects>
        <!-- weave in just this aspect -->
        <aspect name="com.mkyong.saad.LoggingAspect"/>
    </aspects>

</aspectj>

Исходный код аспекта:

public class LoggingAspect {

    public void logBefore(JoinPoint joinPoint) {
        System.out.println("logBefore() is running!");
        System.out.println("hijacked : " + joinPoint.getSignature().getName());
        System.out.println("******");
    }

    public void logAfter(JoinPoint joinPoint) {
        System.out.println("logAfter() is running!");
        System.out.println("hijacked : " + joinPoint.getSignature().getName());
        System.out.println("******");
    }
}

но это не работает, только если я перехожу к конфигу аннотаций. СОС ПЛЗ


person Saad Fch    schedule 10.01.2016    source источник
comment
Пожалуйста, добавьте также исходный код аспекта и убедитесь, что ваш класс CustomerBoImpl не пропускает первую строку самого объявления класса.   -  person Nándor Előd Fekete    schedule 11.01.2016
comment
привет, я просто добавляю код для аспекта и добавляю первую строку CustomerBoImpl cn помогите мне, пожалуйста :)   -  person Saad Fch    schedule 11.01.2016


Ответы (1)


удалите следующий код в файле aop.xml, затем запустите jvm с такими аргументами: -javaagent:"yourpath/spring-instrument-***.jar"

<weaver>
    <!-- only weave classes in our application-specific packages -->
    <include within="com.mkyong.saad.*"/>
</weaver>
person Tao Li    schedule 11.07.2019