Manually inject dependencies with Spring

// You can create the Factory from the Application context ApplicationContext springContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContextEvent.getServletContext()); AutowireCapableBeanFactory factory = springContext.get(AutowireCapableBeanFactory.class); //OR it's possible to autowire the Factory directly @Autowired AutowireCapableBeanFactory factory; // 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.