protected void initPropertiesPlaceHolder( ConfigurableApplicationContext context, AcServiceConfig serviceConfig) { // prepare properties from service config Properties prop = new Properties(); for (String key : serviceConfig.getKeys()) { // NOTE: use data from service property (preferences + default) prop.setProperty(key, serviceConfig.getProperty(key)); } // TODO (other better way) other core reserved properties prop.setProperty( "ac.context.sessionId", String.valueOf(serviceConfig.getCoreContext().getSession().getSessionId())); prop.setProperty( "ac.context.profileId", String.valueOf(serviceConfig.getCoreContext().getSession().getProfile().getProfileId())); PropertyPlaceholderConfigurer propConfig = new PropertyPlaceholderConfigurer(); propConfig.setProperties(prop); context.addBeanFactoryPostProcessor(propConfig); }
protected ApplicationContext prepareParentContext(final AcServiceConfig serviceConfig) throws AcServiceException { AcCoreContext coreContext = serviceConfig.getCoreContext(); GenericApplicationContext parentContext = new GenericApplicationContext(); DefaultListableBeanFactory beanFactory = parentContext.getDefaultListableBeanFactory(); // add service config beanFactory.registerSingleton(AcServiceConfig.SERVICE_CONFIG_BEAN_NAME, serviceConfig); // add core context beanFactory.registerSingleton(AcServiceConfig.CORE_CONTEXT_BEAN_NAME, coreContext); // add session beanFactory.registerSingleton(AcServiceConfig.SESSION_BEAN_NAME, coreContext.getSession()); // add profile beanFactory.registerSingleton( AcServiceConfig.PROFILE_BEAN_NAME, coreContext.getSession().getProfile()); // add data repository beanFactory.registerSingleton( AcServiceConfig.REPOSITORY_BEAN_NAME, coreContext.getDataRepository()); // add service preferences beanFactory.registerSingleton( AcServiceConfig.PREFERENCES_BEAN_NAME, serviceConfig.getServicePreferences()); // add dictionary beanFactory.registerSingleton( AcServiceConfig.DICTIONARY_BEAN_NAME, coreContext.getSession().getProfile().getDictionary()); for (String serviceClassName : metadata().getDependsServiceClassNames()) { try { AcService dependService = coreContext.getServiceByClassName(serviceClassName); beanFactory.registerSingleton(serviceClassName, dependService); } catch (Exception e) { throw new AcServiceException("load depend service error: " + serviceClassName, e); } } // ready for parent context parentContext.refresh(); return parentContext; }