내를 자동 설정할 수 있습니다. 컨트롤러 메서드를 호출하기 전에 @Around 메서드에서 역할을 채 웁니다. 나중에 다른 권한 부여 검사를 위해이 역할에 액세스해야합니다.봄 요청이 난 단지 사용자의 역할을 포함하는 단일 요청에 대한 유효 빈을 만들기 위해 노력하고 @Around
org.springframework.beans.factory.BeanCreationException :
@Component
@Aspect
public class SecurityAudit {
@Autowired
private CurrentRoles currentRoles;
@Around("@annotation(requestMapping) && execution(*
com.myapp.controller..*.*(..))")
public Object around(ProceedingJoinPoint pjp, RequestMapping requestMapping)
throws Throwable {
...
...
//I populate the roles with a db lookup. They will be referenced here, and later in controller methods as-needed.
}
}
package com.myapp.model;
...
...
@JsonInclude(JsonInclude.Include.NON_NULL)
@Generated("org.jsonschema2pojo")
@JsonPropertyOrder({
"sso",
"roles"
})
@Component
@Scope(value="request", proxyMode=ScopedProxyMode.TARGET_CLASS)
public class CurrentRoles {
@JsonProperty("roles")
private Set<Role> roles;
...
...
}
나는 다음과 같은 얻을 이름으로 만드는 중 오류 콩 'securityAudit'를 autowire 종속성 주입 실패; 상자의 예외는 org.springframework.beans.factory.BeanCreationException입니다 : 필드 autowire하기 수 없습니다 : 개인 com.myapp.model.CurrentRoles의 com.myapp.currentRoles을; 종속성 검색 결과 [com.myapp.model.CurrentRoles] 된 타입의 적격 콩 : 예상 적어도 1 빈 의존성이 자동으로 묶어 후보로서 자격이 중첩 예외 org.springframework.beans.factory.NoSuchBeanDefinitionException이다. 종속성 주석 : 가로 세로가 시작시 생성
{org.springframework.beans.factory.annotation.Autowired @는 (= TRUE 필수)}. 요청이 들어오는 시작할 때까지 주입 요청 범위의 빈 그때 내가 특정 요청에 대한 currentRoles 빈을 채울 수, 널있을 것이지만 나는 것이다.