I look at the Jetty / Tutorial / Embedding Jetty Documentation . You probably mean the challenge ServletContextHandler.addServlet(). You have few options:
@Configuration (starting from 3.0)
My favorite approach. You can customize everything with Java!
@Configuration
public class Jetty {
@Bean(initMethod = "start")
public Server server() {
Server server = new Server(8080);
server.setHandler(context());
return server;
}
@Bean
public ServletContextHandler context() {
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.addServlet(servlet(), "/*");
return context;
}
@Bean
public ServletHolder servletHolder() {
return new ServletHolder(helloServlet());
}
@Bean
public HelloServlet helloServlet() {
return new HelloServlet();
}
}
Inheritance / decoration
ServletContextHandler, Java bean. , , Jetty Spring - . , , , - ?
, . bean, :
<bean id="javaVersion" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="servletContextHandler"/>
<property name="targetMethod" value="addServlet"/>
<property name="arguments">
<list>
<ref bean="yourServlet"/>
</list>
</property>
</bean>