apache / apache/grails-core

Found 3 beans for type interface org.springframework.security.authentication.AuthenticationManager, but none marked as primary

Open
#12,376 13 comments 0 reactions 0 assignees View on GitHub
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

### Issue description

After upgrading my running application from Grails 4.0.6 to Grails 5.1.2, it refuse to start up.
Stacktrace:

07.02.2022 16:08:47.278 [restartedMain] ERROR o.s.boot.SpringApplication - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'managementSecurityFilterChain' defined in class path resource [org/springframework/boot/actuate/autoconfigure/security/servlet/ManagementWebSecurityAutoConfiguration.class]: Unsatisfied dependency expressed through method 'managementSecurityFilterChain' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.HttpSecurityConfiguration.httpSecurity' defined in class path resource [org/springframework/security/config/annotation/web/configuration/HttpSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.config.annotation.web.builders.HttpSecurity]: Factory method 'httpSecurity' threw exception; nested exception is java.lang.IllegalArgumentException: Found 3 beans for type interface org.springframework.security.authentication.AuthenticationManager, but none marked as primary
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:541)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:302)
at grails.boot.GrailsApp.run(GrailsApp.groovy:99)
at grails.boot.GrailsApp.run(GrailsApp.groovy:485)
at grails.boot.GrailsApp.run(GrailsApp.groovy:472)
at grails.boot.GrailsApp$run.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:148)
at io.backend.Application.main(Application.groovy:14)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)

Following are my dependencies:

```
developmentOnly("org.springframework.boot:spring-boot-devtools")
implementation "org.grails:grails-dependencies:$grailsVersion", {
exclude module:'grails-datastore-simple'
}
implementation 'org.springframework.boot:spring-boot-starter-logging'
implementation "org.springframework.boot:spring-boot-starter-validation"
implementation 'org.springframework.boot:spring-boot-autoconfigure'
implementation 'org.grails:grails-core'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
providedCompile 'org.springframework.boot:spring-boot-starter-tomcat'
implementation 'org.grails:grails-plugin-url-mappings'
implementation 'org.grails:grails-plugin-rest'
implementation 'org.grails:grails-plugin-codecs'
implementation 'org.grails:grails-plugin-interceptors'
implementation 'org.grails:grails-plugin-services'
implementation 'org.grails:grails-plugin-datasource'
implementation 'org.grails:grails-plugin-databinding'
implementation 'org.grails:grails-web-boot'
implementation 'org.grails:grails-logging'
implementation 'org.grails.plugins:cache'
implementation 'org.grails.plugins:async'
implementation 'org.grails.plugins:mongodb'
implementation 'org.grails.plugins:events'
implementation 'org.grails.plugins:gsp'
implementation 'org.grails.plugins:views-json'
implementation 'org.grails.plugins:views-json-templates'
compileOnly "io.micronaut:micronaut-inject-groovy"
console "org.grails:grails-console"
profile 'org.grails.profiles:web'
providedCompile 'org.grails.plugins:embedded-mongodb:2.0.0.M1'
implementation 'org.grails:grails-plugin-i18n'
implementation 'org.grails:grails-dependencies'
implementation 'org.grails.plugins:scaffolding'
implementation 'org.grails.plugins:spring-security-rest:3.0.1'
implementation 'org.grails.plugins:spring-security-rest-gorm:3.0.1'
//Mail
implementation 'org.grails.plugins:mail:3.0.0'
//Http clients
String httpclientVersion = '4.5.13' //4.5.12
implementation "org.apache.httpcomponents:httpclient:$httpclientVersion"
implementation "org.apache.httpcomponents:fluent-hc:$httpclientVersion"
implementation "org.apache.httpcomponents:httpclient-cache:$httpclientVersion"
implementation "org.apache.httpcomponents:httpmime:$httpclientVersion"
//GSP renderer
implementation 'org.grails.plugins:rendering:2.0.3'
implementation 'org.xhtmlrenderer:core-renderer:R8'
//Websocket and it's security
implementation 'org.grails.plugins:grails-spring-websocket:2.5.0.RC1'
implementation "org.springframework.security:spring-security-config"
implementation "org.springframework.security:spring-security-messaging"
implementation "org.springframework.security:spring-security-web"
runtimeOnly 'org.springframework:spring-test:4.2.1.RELEASE'
//AWS: S3, SQS
implementation 'org.grails.plugins:aws-sdk-s3:2.4.8'
implementation 'org.grails.plugins:aws-sdk-sqs:2.4.8'
//Oauth2 provider
implementation 'org.grails.plugins:spring-security-oauth2-provider:4.0.0-RC1'
implementation 'javax.xml.bind:jaxb-api:2.3.1'
implementation 'javax.activation:activation:1.1.1'
implementation 'org.glassfish.jaxb:jaxb-runtime:2.3.1'
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the startup failure from Application.groovy:14 and reviewing the listed Grails and Spring Security dependencies alongside ManagementWebSecurityAutoConfiguration and HttpSecurityConfiguration in the stack trace. Done means identifying the incompatible or conflicting dependency or configuration and confirming that the application starts successfully without the AuthenticationManager ambiguity.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy, spring-boot
Domain
authentication, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.