【发布时间】:2014-12-02 13:08:19
【问题描述】:
如果程序员返回 Arraylist 而不是列表,我会尝试生成警告。我使用 Spring Boot,Spring Data JPA。
Pojo 示例
@Entity
public class Box {
@Id
@GeneratedValue
private long id;
private long prio;
public long getPrio() {
return prio;
}
public void setPrio(long prio) {
this.prio = prio;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}
我的仓库:
@Repository
public interface BoxRepository extends JpaRepository<Box, Long>{
public List findByPrio(long prio);
}
现在是我的方面:
@Aspect
@Component
public class ReturnList {
@AfterReturning(value = "within(de.fhb.*) && !within(org.springframework.*) && call(* de.fhb..*(..))", returning = "returnValue")
public void logServiceAccess(JoinPoint joinPoint, Object returnValue) {
if (returnValue != null) {
if (returnValue.getClass() != null) {
Class<?> clazz = returnValue.getClass();
if (java.util.List.class.isAssignableFrom(clazz)) {
System.out
.println("Please use List instead of a concrete implementation ( "+ returnValue.getClass() + " ) for method: "
+ joinPoint.getSignature().getName() + ".");
}
}
}
}
}
我的问题
看起来 spring 数据(jpa 存储库)正在返回一个 Arraylist。我不想从 jpa 存储库中捕获方法,我排除了 org.springframework 但如果我运行类似以下行的内容仍会触发方面:
System.out.println(boxRepository.findByPrio(1));
任何将停止触发方面调用 spring jparepository 方法的提示?
【问题讨论】:
标签: java spring-data aspectj spring-data-jpa