2015-11-18 19 views
2

我對Eclipse和AspectJ有相當討厭的問題。在每個改變的方面的影響下,我需要做一個完整的項目重建(清潔)。 任何人都有一個想法,我該如何避免?Eclipse中的AspectJ - 變更後的項目清潔

package pl.xxx.model.entity; 

import java.io.Serializable; 

import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.Id; 
import javax.persistence.Lob; 
import javax.persistence.SequenceGenerator; 
import javax.persistence.Table; 
import javax.persistence.Transient; 

import org.apache.commons.lang3.StringUtils; 

@Entity 
@Table(name="CUSTOMER") 
public class Customer implements Serializable { 

    private static final long serialVersionUID = 9128787620983157104L; 

    @Id 
    @SequenceGenerator(name="IdGenerator", sequenceName="SEQ_CUSTOMER", allocationSize=1) 
    @Column(name="ID", unique=true, nullable=false, precision=15, scale=0) 
    protected Long id; 

    @Column(name="FILE_TYPE", length=3) 
    @CorelatedEnum(IncomingFileType.class) 
    private String fileType; 
} 

錯誤::類型客戶必須實現繼承抽象方法UpdateEntityInterface._getUpdatedFields()Customer.java線17的Java問題

+1

這聽起來像一個AspectJ的bug,增量編譯器沒有作出正確的決定。您是否嘗試過使用'@ DeclareMixin'而不是'@ DeclareParents' - 它應該實現類似的功能,但我只是想知道增量編譯是否更好地處理了mixin的情況。新的AspectJ錯誤在這裏:https://bugs.eclipse.org/bugs/enter_bug.cgi?product=AspectJ –

+0

它與@DeclareMixin合作!謝謝你,兄弟。你救了我很多重建。 –

回答

0
  1. 使用安迪

    package pl.xxx.infrastructure.jdbc; 
    
    import org.aspectj.lang.JoinPoint; 
    import org.aspectj.lang.annotation.Aspect; 
    import org.aspectj.lang.annotation.Before; 
    import org.aspectj.lang.annotation.DeclareParents; 
    import org.aspectj.lang.annotation.Pointcut; 
    
    import pl.xxx.infrastructure.jdbc.common.UpdateEntityInterface; 
    
    @Aspect 
    public class UpdateEntityAspect { 
    
        /** 
        * Wyszukiwanie wszystkich klas z adnotacją Entity 
        */ 
        @Pointcut("within(@javax.persistence.Entity pl.xxx..*)") 
        public void beanAnnotatedWithEntity() { 
        } 
    
        /** 
        * Wyszukiwanie wszystkich metod z nazwą rozpoczynającą się od set 
        */ 
        @Pointcut("execution(public * set*(..))") 
        public void setMethod() { 
        } 
    
        /** 
        * Wyszukiwanie wszystkich pol w momencie zmodyfikacji ich stanu 
        */ 
        @Pointcut("set(private * *)") 
        public void privateField() { 
        } 
    
        /** 
        * Nadawanie encji dodatkowego interfejsu/wstrzykiwanie dodatkowych pol 
        */ 
        @DeclareParents(value = "@javax.persistence.Entity pl.xxx..*", defaultImpl = UpdateEntityInterface.UpdateEntityInterfaceImpl.class) 
        UpdateEntityInterface updateEntityInterface; 
    
        /** 
        * Kod wstrzykiwany podczas modyfikowania pola encji 
        * 
        * @param joinPoint 
        * @param entity 
        */ 
        @Before("beanAnnotatedWithEntity() && privateField() && target(entity)") 
        public void onSetExecuted(JoinPoint joinPoint, Object entity) { 
         if (entity instanceof UpdateEntityInterface) { 
          UpdateEntityInterface updateEntityInterface = (UpdateEntityInterface) entity; 
          updateEntityInterface._markUpdated(joinPoint.getSignature().getName()); 
         } 
        } 
    
    } 
    

    下方面影響,積極挖掘類Clement解決方案 - DeclareMixin而不是DeclareParents

  2. 嘗試將您的方面類放入o它的lib(項目)作爲默認的彈簧方面。如果您哈瓦Maven項目,你可以將它們添加如下

    <plugin> 
         <groupId>org.codehaus.mojo</groupId> 
         <artifactId>aspectj-maven-plugin</artifactId> 
         <configuration> 
          <aspectLibraries> 
           <aspectLibrary> 
            <groupId>...</groupId> 
            <artifactId>...</artifactId> 
           </aspectLibrary> 
          </aspectLibraries> 
         </configuration> 
        </plugin>