@Component(service = Servlet.class, property = {"alias=/example"})
public class ExampleServlet extends HttpServlet {
@Reference
private ExampleService exampleService;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String result = exampleService.getData();
response.getWriter().print(result);
}
}
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0"
name="ExampleServlet">
<implementation class="com.example.ExampleServlet"/>
<service>
<provide interface="javax.servlet.Servlet"/>
</service>
<reference name="exampleService" interface="com.example.ExampleService"
bind="setExampleService" unbind="unsetExampleService"/>
</scr:component>