Spring request scoped bean failed to be autowired within @Around -
i trying create bean valid single request contains user's roles. populate roles in @around method prior calling controller methods. need access these roles later other authorization checks.
@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 roles db lookup. referenced here, , 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; ... ... }
i following:
org.springframework.beans.factory.beancreationexception: error creating bean name 'securityaudit': injection of autowired dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: not autowire field: private com.myapp.model.currentroles com.myapp.currentroles; nested exception org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type [com.myapp.model.currentroles] found dependency: expected @ least 1 bean qualifies autowire candidate dependency. dependency annotations: {@org.springframework.beans.factory.annotation.autowired(required=true)}
the aspect created @ startup. have though injected request-scoped bean stay null until requests start coming in, populate currentroles bean specific request.
most forgot @service annotation in service class ;)
Comments
Post a Comment