2010-11-18 8 views
5

tanımlar :yay + AspectJ'yi i</p> <p>Bütün kişiler paketi data.entity</p> <p>bir olan zaman @Entity için bir yöntem, bir @Around yönü tanımlamak istiyoruz böyle bir yönünü tanımlayan bir yönünü @Around

@Aspect 
public class TestAspect { 

    @Around("execution(* data.entity..*(..))") 
    public Object aroundAdvice(ProceedingJoinPoint pjp) throws Throwable { 
     System.out.println("INTERCEPT: "+pjp.toLongString()); 
     return pjp.proceed(); 
    } 
} 

Ama hiçbir zaman engellenmez ... Hatam nerede? bahar xml olarak

i bu var:

<?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:tx="http://www.springframework.org/schema/tx" 
     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-3.0.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-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"> 

    <context:component-scan base-package="data.dao, data.service" /> 

    <tx:annotation-driven proxy-target-class="true"/> 

    <aop:aspectj-autoproxy/> 

    <bean id="testAspect" class="spring.TestAspect" /> 

    ... datasource and other ... 

</beans> 

Ben de

@Around("target(data.entity.MyEntity)") 

ve

@Around("target(data.entity..)") 

ama yine de çalışmıyor

deneyin.

Teşekkürler.

cevap

3

Spring-proxy-aop kullanıyorsunuz. Bu, yalnızca sınıf bir yay güdümlü fasulye ise ve önerilen yöntemin başka bir nesneden çağrılması gerektiğinde çalışır.

Yay-proxy-aop yerine gerçek AspectJ kullanmayı deneyin. Sadece aşağıda AOP kullanarak başlattıktan ve

0

i gerekli kavanoz dosyaları, aspectjweaver-1.6.10.jar ve org.springframework.aop-3.0 var varsayıyorum benim seviyeme

  1. de bulgulardır. 5.RELEASE.jar, uygulama sınıf yolunuzda mevcut.

  2. Şu anda tanımladığınız gibi, Prosedür çevresindeki yöntem mükemmeldir.

  3. Aşağıdaki satırı kaldırabilir ve deneyebilirsiniz.

    < bağlam: bileşen tarama baz paket = "data.dao, data.service"/>

İlgili konular