2017-04-07 5 views
0

ユーザーの役割を含む単一のリクエストに対してのみ有効なBeanを作成しようとしています。どのコントローラメソッドを呼び出す前に@Aroundメソッドでロールを設定します。後で他の権限チェックのためにこれらのロールにアクセスする必要があります。@Around内でSpringリクエストのスコープ付きBeanをautowiredにできません

@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; 

    ... 
    ... 

} 

私は、次を得る:

org.springframework.beans.factory.BeanCreationException:エラーは、名前のBeanを作成する 'securityAudit':autowired依存性の注入に失敗しました。ネストされた例外はorg.springframework.beans.factory.BeanCreationExceptionです:フィールドをautowireできませんでした:private com.myapp.model.CurrentRoles com.myapp.currentRoles;ネストされた例外はorg.springframework.beans.factory.NoSuchBeanDefinitionExceptionです:[com.myapp.model.CurrentRoles]タイプの適格なBeanが依存関係で見つかりませんでした:この依存関係のautowire候補となる少なくとも1つのbeanが必要です。依存関係注釈:{@ org.springframework.beans.factory.annotation.Autowired(必須= true)}

アスペクトは起動時に作成されます。私は、リクエストされたリクエストスコープのBeanはリクエストが入ってくるまでヌルのままですが、特定のリクエストのためにcurrentRoles Beanに値を設定できます。

答えて

0

サービスクラスの@Service注釈を忘れている可能性があります;

関連する問題