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

ktecyv1j  于 2022-11-11  发布在  Spring
关注(0)|答案(2)|浏览(114)

我已经在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$1.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。

g6ll5ycj

g6ll5ycj1#

看起来你还没有配置插件。你需要在你的应用程序中配置插件。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.UserRole和com. yourProject. Roles。基本配置可以使用q2-quickstart脚本创建:

grails s2-quickstart com.yourProject User Role

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

tktrz96b

tktrz96b2#

出现此错误的另一个原因:
您应该使用以下命令:

编译'org.grails.plugins:Spring安全核心:3.1.2'

而不是这个:

实现'org.grails.plugins:安全核心:3.1.2'。

  • 等级:3.4.1,Grails:3.2.13

相关问题