Hi,

In my email about ideas what to do for Wicket 10 (
https://markmail.org/message/vpptsmt4ysxbktzc) I have suggested to
drop @SpringBean and use jakarta.inject.Inject/Named instead.
While working on it I've faced one issue - there is no support for
non-required bean:

@SpringBean(required = false)
private SomeBean someBean;

If there is no matching bean in the Spring application context then nothing
will be injected. Without 'required = false' the instantiation of the
Component will fail with an Exception.

With jakarta.inject APIs there is no way to say that something is optional.
I've tried by using java.util.Optional:

@Inject
private Optional<SomeBean> someBean;

but the problem here is that j.u.Optional is a final class and cannot be
enhanced by CGLib to create a serializable proxy around it.

Another option is to create a custom annotation, e.g. @Optional in
wicket-ioc.

Do you have other ideas ?
Or should we stay with @SpringBean or even use Spring's @Autowired ?!

Martin

Reply via email to