You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#15547 brought an awesome improvement to support @Bean in Java8 default methods of interfaces. In the end I currently still have to implement an @Configuration class that implements the interfaces. Assuming that all methods of the interface(s) are default method implementing the @Configuration class is just unnecessary code if it just implements one interface. Why not have support directly for
This was already slightly discussed in #15547 but considered out of scope.
The major advantage of (miss)using interfaces for configs is that you can:
use inheritance instead of @Import what is more natural and even more safe as the compiler can detect conflicts.
as an end-user of a flexible designed library just define your config by extending according @Configuration interfaces from the library but still selectively override @Bean methods where ever you want to customize. When using @Import this is not easily possible.
as an author of a library you can provide your @Configuration objects in such a flexible way as interfaces but without the burden to have a corresponding class for each interface that does noting but implement the interface. If you have a very modular library you might have many @Configuration objects (see e.g. add spring @Configuration classes m-m-m/util#178).
To summarize I like to propose that with Java8 the interface is the new top-level language element. It would be great to see this even more supported by spring. I already use default methods to implement QueryDSL queries in default methods with pure interfaces and no single repository implementation class. This already works today with current spring releases (Thanks guys for your great work). See also m-m-m/util#163 for more advanced usage of Java8 interfaces.
joerg.hohwiller@googlemail.com opened SPR-14220 and commented
#15547 brought an awesome improvement to support
@Beanin Java8 default methods of interfaces. In the end I currently still have to implement an@Configurationclass that implements the interfaces. Assuming that all methods of the interface(s) are default method implementing the@Configurationclass is just unnecessary code if it just implements one interface. Why not have support directly forThis was already slightly discussed in #15547 but considered out of scope.
The major advantage of (miss)using interfaces for configs is that you can:
@Importwhat is more natural and even more safe as the compiler can detect conflicts.@Configurationinterfaces from the library but still selectively override@Beanmethods where ever you want to customize. When using@Importthis is not easily possible.@Configurationobjects in such a flexible way as interfaces but without the burden to have a corresponding class for each interface that does noting but implement the interface. If you have a very modular library you might have many@Configurationobjects (see e.g. add spring @Configuration classes m-m-m/util#178).To summarize I like to propose that with Java8 the interface is the new top-level language element. It would be great to see this even more supported by spring. I already use default methods to implement QueryDSL queries in default methods with pure interfaces and no single repository implementation class. This already works today with current spring releases (Thanks guys for your great work). See also m-m-m/util#163 for more advanced usage of Java8 interfaces.
Affects: 4.2.5
Issue Links:
@Configuration(prefix = "aabb") (or: how to create reusable configurations)@Beanon Java 8 default methods in interfaces0 votes, 5 watchers