Page History
...
Info |
---|
DI.1.8 § Servletten skal autowires programatisk via ApplicationContext'en |
Dette er demonstreret ved NotificationBroker-servletten her:
Code Block | ||||
---|---|---|---|---|
| ||||
@WebServlet("/*")
public class NotificationBrokerServlet extends HttpServlet {
...
@Override
public void init() throws ServletException {
Object o = getServletContext().getAttribute(NotificationBrokerServletContextListener.ANNOTATION_CONFIG_CONTEXT);
if(o != null && o instanceof AnnotationConfigApplicationContext) {
((AnnotationConfigApplicationContext)o).getAutowireCapableBeanFactory().autowireBean(this);
}
}
|
Afsluttende
Samlet set udgør dokumentet her med eksempler en vejledning til hvordan DI i NSP's java-komponenter skal håndteres med brug af konfigurationsklasser, beans, autowiring og AnnotationConfigApplicationContext / AnnotationConfigWebApplicationContext.