List of usage examples for org.springframework.beans.factory.config AutowireCapableBeanFactory autowireBean
void autowireBean(Object existingBean) throws BeansException;
From source file:org.jnap.core.mvc.async.AsyncRequestInterceptor.java
/** * //from w w w.j av a2 s . c o m * @param listenerTypes * @return */ protected AtmosphereResourceEventListener[] createListeners( Class<? extends AtmosphereResourceEventListener>[] listenerTypes) { AtmosphereResourceEventListener[] listeners = null; if (listenerTypes != null) { listeners = new AtmosphereResourceEventListener[listenerTypes.length]; AtmosphereResourceEventListener listener = null; AutowireCapableBeanFactory autowireCapableBeanFactory = null; try { autowireCapableBeanFactory = applicationContext.getAutowireCapableBeanFactory(); } catch (IllegalStateException e) { // ignore; listeners will not be inject with spring beans } for (int i = 0; i < listenerTypes.length; i++) { Class<? extends AtmosphereResourceEventListener> listenerType = listenerTypes[i]; listener = BeanUtils.instantiate(listenerType); if (autowireCapableBeanFactory != null) { autowireCapableBeanFactory.autowireBean(listener); } listeners[i] = listener; } } return listeners; }
From source file:org.mitre.mpf.app.ComponentRegistrationApp.java
/** * Register one or more components. Updates the Algorithms.xml, Actions.xml, Tasks.xml, Pipelines.xml, * nodeServicesPalette.json, and nodeManagerConfig.xml files. * * @param args args[0] contains the path to the cpp component list; * args[1] contains the number of services per component that should be configured * args[2] contains the node manager hostname to use in nodeManagerConfig.xml * args[3] (optional) contains the string of user-specified components *//* w ww . j av a2 s . c om*/ public static void main(String[] args) { // NOTE: "-DcppComponents=<blank>" is the same as not providing the option if (args.length != 3 && args.length != 4) { System.err.println("Usage: java " + ComponentRegistrationApp.class.getSimpleName() + " component-list-file num-services-per-component node-manager-hostname [\"componentA,componentB,componentC,...\"]"); System.exit(-1); } String componentListPath = args[0]; if (!Files.exists(Paths.get(componentListPath))) { System.err.println("Cannot read: " + componentListPath); System.exit(-1); } List<String> componentPaths = null; try { componentPaths = Files.readAllLines(Paths.get(componentListPath), StandardCharsets.UTF_8); } catch (IOException e) { e.printStackTrace(); System.exit(-1); } int numServicesPerComponent = 1; try { numServicesPerComponent = Integer.parseInt(args[1]); } catch (NumberFormatException e) { e.printStackTrace(); System.exit(-1); } String nodeManagerHostname = args[2]; if (args.length == 4) { String componentsSpecified = args[3]; List<String> componentsSpecifiedList = Arrays.asList(componentsSpecified.split(",")); List<String> componentsSpecifiedInFileList = componentPaths.stream() .map(c -> FilenameUtils.getBaseName(c)).collect(Collectors.toList()); // sanity check if (!componentsSpecifiedInFileList.containsAll(componentsSpecifiedList)) { System.err.println( "The specified components " + componentsSpecifiedList + " are not a subset of those in " + componentListPath + " " + componentsSpecifiedInFileList + "."); System.err.println("Do a full MPF clean and build."); System.exit(-1); } // filter out components that were built, but should not be registered componentPaths = componentPaths.stream() .filter(c -> componentsSpecifiedList.contains(FilenameUtils.getBaseName(c))) .collect(Collectors.toList()); } // performance optimization: load the application context once ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-minimal.xml"); AutowireCapableBeanFactory beanFactory = context.getAutowireCapableBeanFactory(); AddComponentService addComponentService = context.getBean(AddComponentService.class); beanFactory.autowireBean(addComponentService); NodeManagerService nodeManagerService = context.getBean(NodeManagerService.class); beanFactory.autowireBean(nodeManagerService); for (String componentPath : componentPaths) { // TODO: Handle caffe in the same way as the other components, then remove this check. // TODO: Ansible should prompt the user to install each and every component in the deployment package. String componentName = FilenameUtils.getBaseName(componentPath); if (componentName.equals("caffeComponent")) { continue; } String descriptorPath = componentPath + "/descriptor.json"; System.out.println("Registering: " + descriptorPath); try { // update Algorithms.xml, Actions.xml, Tasks.xml, Pipelines.xml, and nodeServicesPalette.json addComponentService.registerDeployedComponent(descriptorPath); } catch (Exception e) { e.printStackTrace(); System.exit(-1); // kill the build if anything goes wrong } } if (numServicesPerComponent > 0) { Map<String, ServiceModel> nodeServiceModels = nodeManagerService.getServiceModels(); for (ServiceModel serviceModel : nodeServiceModels.values()) { serviceModel.setServiceCount(numServicesPerComponent); } NodeManagerModel nodeManagerModel = new NodeManagerModel(nodeManagerHostname); nodeManagerModel.setServices(new ArrayList(nodeServiceModels.values())); List<NodeManagerModel> nodeManagerModels = new ArrayList<NodeManagerModel>(); nodeManagerModels.add(nodeManagerModel); try { // update nodeManagerConfig.xml nodeManagerService.saveNodeManagerConfig(nodeManagerModels, false); // don't reload NodeManagerStatus } catch (Exception e) { e.printStackTrace(); System.exit(-1); // kill the build if anything goes wrong } } }
From source file:org.projectforge.business.teamcal.servlet.CalendarAboServlet.java
@Override public void init(final ServletConfig config) throws ServletException { super.init(config); springContext = WebApplicationContextUtils.getRequiredWebApplicationContext(config.getServletContext()); final AutowireCapableBeanFactory beanFactory = springContext.getAutowireCapableBeanFactory(); beanFactory.autowireBean(this); }
From source file:org.projectforge.business.user.filter.UserFilter.java
@Override public void init(final FilterConfig filterConfig) throws ServletException { WebApplicationContext springContext = WebApplicationContextUtils .getRequiredWebApplicationContext(filterConfig.getServletContext()); final AutowireCapableBeanFactory beanFactory = springContext.getAutowireCapableBeanFactory(); beanFactory.autowireBean(this); CONTEXT_PATH = filterConfig.getServletContext().getContextPath(); WICKET_PAGES_PREFIX = CONTEXT_PATH + "/" + Const.WICKET_APPLICATION_PATH; // IGNORE_PREFIX_WICKET = WICKET_PAGES_PREFIX + "resources"; // IGNORE_PREFIX_DOC = contextPath + "/secure/doc"; // IGNORE_PREFIX_SITE_DOC = contextPath + "/secure/site"; IGNORE_PREFIX_LOGO = CONTEXT_PATH + "/" + LogoServlet.BASE_URL; IGNORE_PREFIX_SMS_REVEIVE_SERVLET = CONTEXT_PATH + "/" + SMSReceiverServlet.URL; }
From source file:ubicrypt.core.Utils.java
public static <T> T springIt(ConfigurableApplicationContext ctx, T object, String name) { final AutowireCapableBeanFactory factory = ctx.getAutowireCapableBeanFactory(); factory.autowireBean(object); factory.applyBeanPostProcessorsBeforeInitialization(object, name); factory.applyBeanPostProcessorsAfterInitialization(object, name); return object; }