Manually inject dependencies with Spring

ApplicationContext springContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContextEvent.getServletContext()); AutowireCapableBeanFactory factory = springContext.get(AutowireCapableBeanFactory.class); // this would instantiate and autowire a bean: UserDAO userDAO = factory.createBean(UserDAO.class); // this will autowire an already existing bean: UserDAO manualUserDAO = new UserDAO(); factory.initializeBean(manualUserDAO, "beanNameIfNeeded");

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.