Hi Lon,
Yeah, we need to make this a bit more transparent (servlet-related API is still
minimal, as we focsed on other areas like web services). But you are going in
the right direction. JettyModule.contributeServlets(Binder) is what you need.
We wrap the servlet in Bootique MappedServlet class to attach the URL mapping.
So the whole thing may look like this:
public class App implements Module {
@Override
public void configure(Binder binder) {
Set<String> urlPatterns = Collections.singleton("/*");
MyServlet servlet = new MyServlet();
JettyModule.contributeServlets(binder).addBinding().toInstance(new
MappedServlet(servlet, urlPatterns));
}
}
Since you create the servlet in the code, you don't need init parameters.
Instead you treat the servlet as a Java object, and pass anything you need in
constructor or via setters. (The whole point is to avoid web.xml).
We may improve this API in the future (a bit too much code for my liking; also
servlet has to be instantiated and initialized manually instead of using
injection). But it is fully functional and will get you going.
Andrus
> On Mar 9, 2016, at 6:28 PM, Lon Varscsak <[email protected]> wrote:
>
> I also need to add init parameters to my servlet, but I only know how to do
> it through ServletHolder (which bootique doesn’t support).
>
> -Lon
>
> On Wed, Mar 9, 2016 at 3:11 PM, Lon Varscsak <[email protected]> wrote:
>
>> Since I can’t find an email list for Bootique… :D
>>
>> How do I add a servlet to Jetty through Bootique. I see
>> JettyModule.contributeServlets(Binder)…but I can’t figure it out. DI is
>> still magical to me.
>>
>> Thanks,
>>
>> Lon
>>