the.fine
07/06/2017, 2:09 PMthe.fine
07/06/2017, 2:11 PMdh44t
07/06/2017, 2:25 PMroberto.guerra
07/06/2017, 3:31 PMroberto.guerra
07/06/2017, 3:31 PMthe.fine
07/06/2017, 4:22 PMdh44t
07/06/2017, 4:23 PMmichael.barker
07/06/2017, 4:55 PMorangy
sdeleuze
07/06/2017, 8:47 PMsdeleuze
07/06/2017, 8:48 PMsdeleuze
07/06/2017, 8:48 PMorangy
sdeleuze
07/06/2017, 8:49 PMsdeleuze
07/06/2017, 8:50 PMziad
07/07/2017, 5:34 PM@Bean
fun init(dataSource: DataSource) = CommandLineRunner {
//Do things with DataSource
}
Intellij gives me a warning: “Could not autowire. There is more than one bean of ‘DataSource’ type.”
I’m trying to understand what to do about this. I’m particularly confused because of the following:
1) This compiles and runs correctly.
2) If I change the injection to constructor injection rather than injecting into the init function, the IDE stops giving warnings.
3) I have an import statement for DataSource defined, which I assumed would help resolve the ambiguity for the IDE. import javax.sql.DataSource
ziad
07/07/2017, 5:34 PMjk
07/08/2017, 6:33 PMjk
07/08/2017, 6:34 PMDataSource @Autowire warning in Java▾
ziad
07/10/2017, 9:06 AMziad
07/10/2017, 9:06 AMsdeleuze
07/11/2017, 12:43 PMApplicationContext
extensions (see https://spring.io/blog/2017/01/04/introducing-kotlin-support-in-spring-framework-5-0#functional-bean-registration-with-kotlin). While the syntax is much shorter than in Java, I was still puzzled by the fact this way of declaring beans was not declarative, and would maybe be worth introducing a lightweight Kotlin DSL to get a 100% idomatic Kotlin syntax. I plan to introduce it as part of that pull request (https://github.com/spring-projects/spring-framework/pull/1473) that allows to declare your beans as following:
beans {
bean<Foo>()
bean<Bar>("bar")
if (env.activeProfiles.contains("baz")) {
bean { Baz(it.ref<Bar>()) }
bean { Baz(it.ref("bar")) }
}
}
Advantages compared to Regular ApplicationContext
API are:
- No exposure of low-level ApplicationContext
API Focused DSL easier to read, but also easier to write with fewer entries in the auto-complete
- Declarative syntax instead of functions with verbs like registerBean
while still allowing programmatic registration of beans with if expressions or for loops
- Such DSL is idiomatic in Kotlin
- No need to have an ApplicationContext
instance to write how you register your beans since beans { }
DSL is conceptually a Consumer<ApplicationContext>
Any feedbacks is welcome. Do you like such DSL? Are you ok with the syntax? Any issue to raise?kenkyee
07/11/2017, 12:57 PMkenkyee
07/11/2017, 12:57 PMsdeleuze
07/11/2017, 12:59 PMsdeleuze
07/11/2017, 12:59 PMAPplicationContext
APInekoinemo
07/11/2017, 1:43 PMroberto.guerra
07/11/2017, 4:14 PMkobalt
as an option to <http://start.spring.io|start.spring.io>
?nfrankel
07/11/2017, 4:44 PMnfrankel
07/11/2017, 4:45 PM