아키텍처의 레이어가 손상되었는지 여부를 확인하기 위해 aspectj를 사용하려고합니다.aspectj 봄 부팅시 깨진 레이어 액세스 확인
이제는 de.fhb.controller 내에서 주석이 달린 autowired에 대한 모든 메소드 호출을 표시합니다.
하지만 어떻게하면 리포지토리로 제한 할 수 있습니까?
패키지 구조는 다음과 같습니다 등등
- de.fhb.controller
- de.fhb.service
- de.fhb.entity 및합니다. 측면에 의해 확인되어야한다
@Repository public interface BoxRepository extends JpaRepository<Box, Long>{ public List findByPrio(long prio); }
및 컨트롤러 :
@RequestMapping("/box") @Controller public class BoxController { @Autowired private BoxRepository boxRepository; // negative example @Autowired private BoxService boxService; @RequestMapping(value = "/") public String list(Model model) { List boxes = boxRepository.findAll(); // negativ example model.addAttribute("boxes", boxes); return "box/list"; }
더 룩 :
내 측면이
@Aspect
public class Layer {
@DeclareError("within(de.fhb.controller..*) && @annotation(org.springframework.beans.factory.annotation.Autowired) ")
private static final String typeWarning = "You try to access through many layers";
}
저장소처럼 보이는 repository at github
패키지de.fhb.controller
또는
de.fhb.repository.BoxRepository
의 반환 유형이 하위 패키지에있는 모든 방법을 절편하지만 코드에서 그러한 방법입니다 :
나는 그것을 내 질문에 편집했습니다. –
그에 따라 답변을 업데이트했습니다. – kriegaex
예, 우리는 이미 fullblown AspectJ를 추가 했으므로 호출이 작동합니다. 고맙습니다! –