Eclipse 中的 AspectJ - 更改后项目清理
AspectJ in Eclipse - project clean after change
我在使用 Eclipse 和 AspectJ 时遇到了非常烦人的问题。在受到方面影响的 class 中的每个更改之后,我需要进行完整的项目重建(清理)。
任何人都知道我该如何避免这种情况?
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());
}
}
}
Class 看点影响:
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;
}
错误:类型 Customer 必须实现继承的抽象方法 UpdateEntityInterface._getUpdatedFields() Customer.java 第 17 行 Java 问题
- 使用 Andy Clement 解决方案 - DeclareMixin 而不是 DeclareParents
尝试将您的方面 类 作为默认 spring 方面放入其他库(项目)中。如果你有 maven 项目,你可以按如下方式添加它们
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<configuration>
<aspectLibraries>
<aspectLibrary>
<groupId>...</groupId>
<artifactId>...</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
</plugin>
我在使用 Eclipse 和 AspectJ 时遇到了非常烦人的问题。在受到方面影响的 class 中的每个更改之后,我需要进行完整的项目重建(清理)。 任何人都知道我该如何避免这种情况?
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());
}
}
}
Class 看点影响:
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;
}
错误:类型 Customer 必须实现继承的抽象方法 UpdateEntityInterface._getUpdatedFields() Customer.java 第 17 行 Java 问题
- 使用 Andy Clement 解决方案 - DeclareMixin 而不是 DeclareParents
尝试将您的方面 类 作为默认 spring 方面放入其他库(项目)中。如果你有 maven 项目,你可以按如下方式添加它们
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <configuration> <aspectLibraries> <aspectLibrary> <groupId>...</groupId> <artifactId>...</artifactId> </aspectLibrary> </aspectLibraries> </configuration> </plugin>