Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info

DI.1.8 § Servletten skal autowires programatisk via ApplicationContext'en

Dette er demonstreret ved NotificationBroker-servletten her:

Code Block
languagejava
titleInitialisering af autowiring
@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.