There are a number of ways I could be doing this instead, but all of them kind of annoy me, this is just a quality of life improvement, would also help I believe with lazy loading of beans.

    springContext.registerBean(Neo4j.class, () -> Neo4jBuilders.newInProcessBuilder()
       .withDisabledServer()
       .build());

    var neo4j = springContext.getBean(Neo4j.class);

what I would like to do is this

   var neo4j =  springContext.registerBean(Neo4j.class, () -> Neo4jBuilders.newInProcessBuilder()
       .withDisabledServer()
       .build());

if changing the method returns from void is not possible, and it probably isn't. I would suggest adding a new method getAndRegisterBean

In this case, I can't use @Bean because my class isn't loaded by spring.

Affects:

./gradlew --version && ./gradlew :app:dependencyInsight --configuration runtimeClasspath --dependency spring-core

------------------------------------------------------------
Gradle 7.1.1
------------------------------------------------------------

Build time:   2021-07-02 12:16:43 UTC
Revision:     774525a055494e0ece39f522ac7ad17498ce032c

Kotlin:       1.4.31
Groovy:       3.0.7
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          11.0.11 (AdoptOpenJDK 11.0.11+9)
OS:           Linux 5.10.42-1-MANJARO amd64

Type-safe dependency accessors is an incubating feature.
Type-safe project accessors is an incubating feature.

> Task :app:dependencyInsight
org.springframework:spring-core:5.3.8

I could probably implement this myself, but I generally prefer to have a thumbs up before I do, and I'd probably just do it the way I'm doing now.

Comment From: sdeleuze

Hi, this kind of use case seems not common enough to be introduced, especially given the pretty clear separation between bean registration and bean access in typical use case.