简体   繁体   中英

Spring Global Method Security And Aspectj

I have finished the configuration of global-method-security which is using @EnableGlobalMethodSecurity(prePostEnabled=true),and now I need to apply aspectj-autoproxy(@EnableAspectJAutoProxy(proxyTargetClass=true)) for some extra method like making a log.But I find these two are conflict with each other.I know the reason for their conflict, but I do not know how to solve it.All these configurations are java-based.Please tell me if you know the solution.Thank you very much!

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled=true)
public class MethodSecurityConfig extends GlobalMethodSecurityConfiguration{
}
---------------------------------------------------------------------------
@Configuration
@EnableAspectJAutoProxy(proxyTargetClass=true)
@ComponentScan
public class AspectConfig {

    @Bean
    public ActionRecord record()
    {
        return new ActionRecord();
    }
}  

WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.event.internalEventListenerProcessor': BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'metaDataSourceAdvisor': Cannot resolve reference to bean 'methodSecurityMetadataSource' while setting constructor argument; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'methodSecurityConfig': Unsatisfied dependency expressed through method 'setObjectPostProcessor' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration': Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: warning no match for this type name: beike.visitorsystem.authority.controller [Xlint:invalidAbsoluteTypeName]
Jan 07, 2018 6:02:30  org.springframework.web.context.ContextLoader initWebApplicationContext
Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.event.internalEventListenerProcessor': BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'metaDataSourceAdvisor': Cannot resolve reference to bean 'methodSecurityMetadataSource' while setting constructor argument; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'methodSecurityConfig': Unsatisfied dependency expressed through method 'setObjectPostProcessor' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration': Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: warning no match for this type name: beike.visitorsystem.authority.controller [Xlint:invalidAbsoluteTypeName]

If you want to include all classes in your package, you need to specify the following in your AspectJ config file: beike.visitorsystem.authority.controller.*

Otherwise, you can just specify beike.visitorsystem.authority.controller.AuthorityController

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM