gridFsTemplate ... required a single bean ... MongoDB

297 views
Skip to first unread message

Fabio Bettiol

unread,
Oct 11, 2021, 4:05:18 AM10/11/21
to CAS Community
Hi.
While trying to deploy Mongo Service Registry and Mongo Ticket Registry (CAS 6.4.0), I get the following error (both services currently working fine in 6.3.2, same server):

Error upon running sudo ./gradle run --info

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 1 of method gridFsTemplate in org.springframework.boot.autoconfigure.data.mongo.MongoDatabaseFactoryDependentConfiguration required a single bean, but 2 were found:
        - mongoDbServiceRegistryTemplate: defined by method 'mongoDbServiceRegistryTemplate' in class path resource [org/apereo/cas/config/MongoDbServiceRegistryConfiguration.class]
        - mongoDbTicketRegistryTemplate: defined in BeanDefinition defined in class path resource [org/apereo/cas/config/MongoDbTicketRegistryConfiguration.class]

Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
>

> Task :run FAILED




From gradle.build:

    implementation "org.apereo.cas:cas-server-support-mongo:${project.'cas.version'}"
    implementation "org.apereo.cas:cas-server-support-mongo-service-registry:${project.'cas.version'}"
    implementation "org.apereo.cas:cas-server-support-mongo-ticket-registry:${project.'cas.version'}"



From cas.proiperties:

# =======================
# MongoDB Vars
# =======================
mongo.db:dbnamehere
mongo.creds:userhere:passwordhere
mongo.hosts:localhost
mongo.uri:mongodb://${mongo.creds}@${mongo.hosts}/${mongo.db}

# =======================
# MongoDB Authentication
# =======================
cas.authn.mongo.client-uri=mongodb://${mongo.creds}@${mongo.hosts}/${mongo.db}
cas.authn.mongo.collection=ticketGrantingTicketsCollection
cas.authn.mongo.database-name=dbnamehere
cas.authn.mongo.host=localhost
cas.authn.mongo.password=passwordhere

# =======================
# MongoDB Ticket registry
# =======================
cas.ticket.registry.mongo.client-uri=mongodb://${mongo.creds}@${mongo.hosts}/${mongo.db}
cas.ticket.registry.mongo.database-name=dbnamehere
cas.ticket.registry.mongo.host=localhost
cas.ticket.registry.mongo.password= passwordhere
cas.ticket.registry.mongo.port=27017

# =======================
# Mongo DB Service registry
# =======================
cas.service-registry.mongo.client-uri=mongodb://${mongo.creds}@${mongo.hosts}/${mongo.db}
cas.service-registry.mongo.collection:casServiceRegistry
cas.service-registry.mongo.database-name=dbnamehere
cas.service-registry.mongo.host=localhost
cas.service-registry.mongo.password= passwordhere


Any help will be appreciated.
Thank you.

Fabio.

Fabio Bettiol

unread,
Oct 18, 2021, 1:48:43 PM10/18/21
to CAS Community, Fabio Bettiol
Hi guys.... Any ... ?

Fabio Bettiol

unread,
Oct 27, 2021, 6:05:07 AM10/27/21
to CAS Community, Fabio Bettiol
Hi.
I managed to solve -temporarily, at least- this issue lowering the version for  to:

build.gradle:

...
implementation 'org.apereo.cas:cas-server-support-mongo-ticket-registry:6.4.0-RC1'
...

Described error on my previous post shows up with the default version for cas 6.4.2

Fabio Bettiol

unread,
Oct 27, 2021, 6:10:02 AM10/27/21
to CAS Community, Fabio Bettiol
Error shows on versions 6.4.0-RC12 and up to 6.5.*

martin....@springer.com

unread,
Jan 19, 2022, 10:21:31 AM1/19/22
to CAS Community, Fabio Bettiol

Hi Fabio,

Any news on your issue? It's now also mine, but again no answer, maybe too trivial or nobody uses MonogDB that way. I run into this problem if using  MongoDB for Service- AND Ticket-Registry AND Spring-Session.
In your case disabling auto config for spring data should fix this, it was actually added with commit https://github.com/apereo/cas/commit/5b65786e50ba3b6c3b7c70b03391fa880072f153

##
# Excluded auto-configuration classes
#
spring.autoconfigure.exclude= \
  org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
  org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration,\
  org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration

But if you instead also need MongoDataAutoConfiguration, i.e. for enabling spring session, the problem is back. Since the bean creation in 6.4.4.2 is not even strictly necessary in my or our case, it is just creating the problem for no reason(?). I patched the modules https://github.com/springernature/cas/commit/15e0b627d6b15faebcdb7f7756339bd60f8bc5e1 to make this also working, but patching is the worst solution imho.
Martin
Reply all
Reply to author
Forward
0 new messages