2015-11-18 22 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>