Is it possible to inject a property bean through a method with a signature doesn’t start with set?
Specifically, I’m trying to use Spring to configure an embedded Jetty instance and I need to be able to inject a servlet bean via an addServlet() method.
I am looking at Jetty/Tutorial/Embedding Jetty documentation. I guess you mean calling
ServletContextHandler.addServlet(). You have few choices:@Configuration(since 3.0)My favourite approach. You can configure everything using Java!
Inheritance/decorating
You can inherit from or wrap original
ServletContextHandlerclass to follow Java bean naming conventions. Of course it requires an extra class, but makes Jetty class Spring-friendly. You can even publish such wrapper or maybe someone already did that?MethodInvokingFactoryBeanI don’t like this approach as it seems too low level. Basically you create a bean that calls arbitrary method with arbitrary arguments: