Grails 3.2.0.M2 spring 应用程序启动时出现安全异常

Grails 3.2.0.M2 spring security exception on application startup

我在 build.gradle 上添加了以下内容以将 spring 安全依赖项添加到我的项目

compile 'org.grails.plugins:spring-security-core:3.1.1'

但是当我启动我的应用程序时,出现以下异常

ERROR org.springframework.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsApplicationPostProcessor' defined in workspace.Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [grails.boot.config.GrailsApplicationPostProcessor]: Factory method 'grailsApplicationPostProcessor' threw exception; nested exception is java.lang.NoClassDefFoundError: grails/plugin/springsecurity/ControllerMixin
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:120)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:681)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:523)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)
    at grails.boot.GrailsApp.run(GrailsApp.groovy:55)
    at grails.boot.GrailsApp.run(GrailsApp.groovy:374)
    at grails.boot.GrailsApp.run(GrailsApp.groovy:363)
    at grails.boot.GrailsApp$run.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
    at workspace.Application.main(Application.groovy:8)

我正在使用 JDK 8 作为我的 sdk。

您似乎还没有配置插件。 您需要在 application.yml 中配置插件 例如:

grails:
  plugin:
    springsecurity:
      userLookup.usernamePropertyName: 'usernameProperty'
      userLookup.userDomainClassName: 'com.yourProject.User'
      userLookup.authorityJoinClassName: 'com.yourProject.UserRole'
      authority.className: 'com.yourProject.Role'
      password:
        algorithm: bcrypt
        encodeHashAsBase64: true
        bcrypt.logrounds: 4
      rejectIfNoRule: true
      successHandler.defaultTargetUrl: /
      controllerAnnotations:
      staticRules:
        - pattern: '/**'
          access: ['permitAll']

您还需要 类 com.yourProject.User、com.yourProject.User角色和 com.yourProject.Role。 可以使用 q2-quickstart 脚本创建基本配置:

grails s2-quickstart com.yourProject User Role

在这里你可以找到非常好的文档 - http://grails-plugins.github.io/grails-spring-security-core/