@Override protected void init() { try { LogSummaryAppenderUtils.registerLogSummaryAppender(); super.init(); this.dataSource = platform.getDataSource(); PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); configurer.setProperties(parameterService.getAllParameters()); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(springContext); ctx.addBeanFactoryPostProcessor(configurer); List<String> extensionLocations = new ArrayList<String>(); extensionLocations.add("classpath:/symmetric-ext-points.xml"); if (registerEngine) { extensionLocations.add("classpath:/symmetric-jmx.xml"); } String xml = parameterService.getString(ParameterConstants.EXTENSIONS_XML); File file = new File(parameterService.getTempDirectory(), "extension.xml"); FileUtils.deleteQuietly(file); if (isNotBlank(xml)) { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); // the "parse" method also validates XML, will throw an exception if misformatted builder.parse(new InputSource(new StringReader(xml))); FileUtils.write(file, xml, false); extensionLocations.add("file:" + file.getAbsolutePath()); } catch (Exception e) { log.error("Invalid " + ParameterConstants.EXTENSIONS_XML + " parameter."); } } try { ctx.setConfigLocations(extensionLocations.toArray(new String[extensionLocations.size()])); ctx.refresh(); this.springContext = ctx; ((ClientExtensionService) this.extensionService).setSpringContext(springContext); this.extensionService.refresh(); } catch (Exception ex) { log.error( "Failed to initialize the extension points. Please fix the problem and restart the server.", ex); } } catch (RuntimeException ex) { destroy(); throw ex; } }
@Before public void createSpringContext() { try { log.info("creating spring context"); PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); Properties properties = new Properties(); properties.setProperty("temp.dir", TMPDIR); configurer.setProperties(properties); ctx = new ClassPathXmlApplicationContext(); ctx.addBeanFactoryPostProcessor(configurer); // ctx.setConfigLocation( // "org/drools/container/spring/beans/persistence/beansVarPersistence.xml" ); ctx.setConfigLocation( "org/drools/container/spring/beans/persistence/beansVarPersistence_Env.xml"); ctx.refresh(); } catch (Exception e) { log.error("can't create spring context", e); throw new RuntimeException(e); } }
public final void loadNode() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(); PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); configurer.setProperties(props); context.addBeanFactoryPostProcessor(configurer); context.setConfigLocation("net\\dfs\\remote\\filestorage\\spring-client.xml"); context.refresh(); context.start(); /* FileLocationTrackerImpl hash = new FileLocationTrackerImpl(); hash.removeAll(); */ log.info("Client Started"); FileReceiverSupport receiveFile = (FileReceiverSupport) context.getBean("receiveFile"); receiveFile.connectJavaSpace(); receiveFile.retrieveFile(); }
/** * 根据配置文件名称获取ApplicationContext * * @param xmlName * @return */ public static ApplicationContext loadContext(String xmlName) { ClassPathXmlApplicationContext context = contexts.get(xmlName); if (context == null) { if (StringUtils.isNotBlank(xmlName)) { List<Object> beanList = new ArrayList<Object>(); context = new ClassPathXmlApplicationContext(); context.setConfigLocation(xmlName); /** 添加BeanFactoryPostProcessor的目的是获得原始的bean对象, 直接getBean拿到的可能是代理后的对象 */ context.addBeanFactoryPostProcessor(createProcessor(beanList)); /** 在初始化之前先把context放到缓存中 防止在初始化过程中存在循环调用,反复初始化 造成程序卡死 */ contexts.put(xmlName, context); context.refresh(); for (Object bean : beanList) { // 解决跨locator的依赖 resolveInjects(bean); } } } return context; }