private SpringContextServiceReference load( final String serviceId, final Map<String, String> updatedProperties) { final String configurationPath = serviceDefinition.getMainContextPath(); final String serviceBeanName = serviceDefinition.getServiceBeanName(); final PropertyPlaceholderConfigurer placeholderConfigurer = createPlaceholderConfigurer(); Properties properties = new Properties(); properties.putAll(updatedProperties); properties.put(ServiceConstants.SERVICE_ID_PROPERTY, serviceId); placeholderConfigurer.setProperties(properties); final GenericXmlApplicationContext context = new GenericXmlApplicationContext(); for(Entry<String, BeanPostProcessor> postProcessorEntry: applicationContext.getBeansOfType(BeanPostProcessor.class).entrySet()){ context.getBeanFactory().registerSingleton(postProcessorEntry.getKey(), postProcessorEntry.getValue()); } context.load(configurationPath); context.setParent(applicationContext); context.addBeanFactoryPostProcessor(placeholderConfigurer); context.registerShutdownHook(); context.refresh(); final SpringContextServiceReference serviceReference; if (StringUtils.isNotBlank(serviceBeanName)) { serviceReference = findBeanByName(serviceBeanName, context); } else { serviceReference = findBeanByClass(context); } return serviceReference; }
private RepositoryService setupRepositoryViaMidPointHome(ConnectionOptions options) { log.info("Initializing repository using midpoint home"); System.setProperty(MIDPOINT_SILENT_PROPERTY_NAME, "true"); String midpointHome = options.getMidpointHome(); String jdbcUrl = options.getUrl(); String jdbcUsername = options.getUsername(); String jdbcPassword = getPassword(options); System.setProperty(MIDPOINT_HOME_OPTION, midpointHome); InitializationBeanPostprocessor postprocessor = new InitializationBeanPostprocessor(); postprocessor.setJdbcUrl(jdbcUrl); postprocessor.setJdbcUsername(jdbcUsername); postprocessor.setJdbcPassword(jdbcPassword); GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); ctx.addBeanFactoryPostProcessor(beanFactory -> beanFactory.addBeanPostProcessor(postprocessor)); ctx.load(CTX_NINJA); ctx.load(CTX_MIDPOINT); ctx.refresh(); context = ctx; return context.getBean(REPOSITORY_SERVICE_BEAN, RepositoryService.class); }