https://kotlinlang.org logo
#spring
Title
c

Czar

12/03/2019, 2:11 PM
Hi, I remember watching some video where speaker was talking about changes in Spring 5.Some.Version. There was something about difference between
Copy code
@Configuration class MyConf(private val someBean: SomeBean) {
    @Bean fun myBean(): MyBean { /* do something with someBean */ }
}
and
Copy code
@Configuration class MyConf {
    @Bean fun myBean(someBean: SomeBean): MyBean { /* do something with someBean */ }
}
But I don't remember either which video it was or what was the difference. Googling around didn't yield any results yet. Does anyone remember/know what I'm talking about?
🤔 1
Ok, I don't remember the video still, but I've found what it was related to, I'm not sure what changed in Spring 5 or in which specific version or if it was only recommendation change, but it involved setting
proxyBeanMethods
to
false
to improve performance here and there. So my examples are not really relevant.
so, given the above, what's preferable?
Copy code
@Configuration(proxyBeanMethods=false)
class MyConfiguration {
    @Bean fun myBean(): MyBean {/*...*/}
}
vs
Copy code
@Component
class MyConfiguration {
    @Bean fun myBean(): MyBean {/*...*/}
}
c

corneil

12/03/2019, 2:57 PM
In first case someBean is injected into the constructor of MyConf while in second case into method call as argument for myBean In general it should not make much of a difference.
Unless for some reason the proxy generation doesn't like that.
c

Czar

12/04/2019, 6:55 AM
@corneil Yeah, that concerns my first example, which as I have iterated is not really relevant. The question is what's better to use in the second example. From reading the docs, effectively they are the same: with
proxyBeanMethods=false
all
@Configuration→@Bean
are lite `@Bean`s as if they were declared in a
@Component
, but maybe I'm missing something.
c

corneil

12/04/2019, 7:19 AM
The question would be. What do you want to achieve?
3 Views