List of usage examples for org.springframework.beans.factory.config PropertyPlaceholderConfigurer PropertyPlaceholderConfigurer
PropertyPlaceholderConfigurer
From source file:com.centeractive.ws.server.core.SoapServer.java
private void configureParentContext() { PropertyPlaceholderConfigurer config = new PropertyPlaceholderConfigurer(); config.setProperties(buildProperties()); context = new ClassPathXmlApplicationContext(); context.addBeanFactoryPostProcessor(config); context.setConfigLocation(SPRING_CONTEXT_LOCATION); context.refresh();/*from w ww.j a v a2 s . c om*/ context.registerShutdownHook(); server = context.getBean(SERVER_BEAN_NAME, Server.class); }
From source file:com.google.enterprise.connector.otex.LivelinkConnectorFactory.java
/** * Create a connector instance.// w ww . java 2s .c o m * This conforms to com.google.enterprise.connector.spi.ConnectorFactory * interface for use by validateConfig(). * * @param config Map of configuration properties */ @Override public Connector makeConnector(Map<String, String> config) throws RepositoryException { try { DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); XmlBeanDefinitionReader beanReader = new XmlBeanDefinitionReader(factory); Resource prototype = new ClassPathResource("config/connectorInstance.xml"); beanReader.loadBeanDefinitions(prototype); // Seems non-intuitive to load these in this order, but we want newer // versions of the connectors to override any default bean definitions // specified in old-style monolithic connectorInstance.xml files. Resource defaults = new ClassPathResource("config/connectorDefaults.xml"); if (defaults != null) { beanReader.loadBeanDefinitions(defaults); } // This code should be using setLocation rather than setProperties, but // that requires the machinery of InstanceInfo.getPropertiesResource. PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); Properties props = new Properties(); props.putAll(config); cfg.setProperties(props); cfg.postProcessBeanFactory(factory); return (Connector) factory.getBean("Livelink_Enterprise_Server"); } catch (Throwable t) { throw new RepositoryException(t); } }
From source file:com.kixeye.chassis.support.test.metrics.cloudwatch.MetricsCloudWatchConfigurationTest.java
@Bean public PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() { return new PropertyPlaceholderConfigurer() { @Override//from w w w. j a v a2s. com protected String resolvePlaceholder(String placeholder, Properties props, int systemPropertiesMode) { return ConfigurationManager.getConfigInstance().getString(placeholder); } }; }
From source file:org.reficio.ws.server.core.SoapServer.java
private void configureParentContext() { PropertyPlaceholderConfigurer config = new PropertyPlaceholderConfigurer(); config.setProperties(buildProperties()); context = new ClassPathXmlApplicationContext(); context.addBeanFactoryPostProcessor(config); context.setConfigLocation(SoapServerConstants.SPRING_CONTEXT_LOCATION); context.refresh();/* w ww . jav a2s . co m*/ context.registerShutdownHook(); server = context.getBean(SoapServerConstants.SERVER_BEAN_NAME, Server.class); }
From source file:net.frontlinesms.FrontlineSMS.java
/** Initialise {@link #applicationContext}. */ public void initApplicationContext() throws DataAccessResourceFailureException { // Load the data mode from the app.properties file AppProperties appProperties = AppProperties.getInstance(); LOG.info("Load Spring/Hibernate application context to initialise DAOs"); // Create a base ApplicationContext defining the hibernate config file we need to import StaticApplicationContext baseApplicationContext = new StaticApplicationContext(); baseApplicationContext.registerBeanDefinition("hibernateConfigLocations", createHibernateConfigLocationsBeanDefinition()); // Get the spring config locations String databaseExternalConfigPath = ResourceUtils.getConfigDirectoryPath() + ResourceUtils.PROPERTIES_DIRECTORY_NAME + File.separatorChar + appProperties.getDatabaseConfigPath(); String[] configLocations = getSpringConfigLocations(databaseExternalConfigPath); baseApplicationContext.refresh();//www .j a v a 2 s . com FileSystemXmlApplicationContext applicationContext = new FileSystemXmlApplicationContext(configLocations, false, baseApplicationContext); this.applicationContext = applicationContext; // Add post-processor to handle substituted database properties PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer(); String databasePropertiesPath = ResourceUtils.getConfigDirectoryPath() + ResourceUtils.PROPERTIES_DIRECTORY_NAME + File.separatorChar + appProperties.getDatabaseConfigPath() + ".properties"; propertyPlaceholderConfigurer.setLocation(new FileSystemResource(new File(databasePropertiesPath))); propertyPlaceholderConfigurer.setIgnoreResourceNotFound(true); applicationContext.addBeanFactoryPostProcessor(propertyPlaceholderConfigurer); applicationContext.refresh(); LOG.info("Context loaded successfully."); this.pluginManager = new PluginManager(this, applicationContext); LOG.info("Getting DAOs from application context..."); groupDao = (GroupDao) applicationContext.getBean("groupDao"); groupMembershipDao = (GroupMembershipDao) applicationContext.getBean("groupMembershipDao"); contactDao = (ContactDao) applicationContext.getBean("contactDao"); keywordDao = (KeywordDao) applicationContext.getBean("keywordDao"); keywordActionDao = (KeywordActionDao) applicationContext.getBean("keywordActionDao"); messageDao = (MessageDao) applicationContext.getBean("messageDao"); emailDao = (EmailDao) applicationContext.getBean("emailDao"); emailAccountDao = (EmailAccountDao) applicationContext.getBean("emailAccountDao"); smsInternetServiceSettingsDao = (SmsInternetServiceSettingsDao) applicationContext .getBean("smsInternetServiceSettingsDao"); smsModemSettingsDao = (SmsModemSettingsDao) applicationContext.getBean("smsModemSettingsDao"); eventBus = (EventBus) applicationContext.getBean("eventBus"); }
From source file:org.nebulaframework.util.spring.NebulaApplicationContext.java
/** * Create a new NebulaApplicationContext using the XML file given and * configures the context using the specified {@code Properties}. * // w ww. ja v a 2 s . c o m * @param configLocation * resource location * @param props * @throws BeansException * if context creation failed */ public NebulaApplicationContext(String configLocation, Properties props) throws BeansException { this(); PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); configurer.setProperties(props); this.addBeanFactoryPostProcessor(configurer); this.setConfigLocation(configLocation); this.refresh(); this.start(); }
From source file:org.pentaho.pat.plugin.PatLifeCycleListener.java
public void loaded() throws PluginLifecycleException { ClassLoader origContextClassloader = Thread.currentThread().getContextClassLoader(); IServiceManager serviceManager = (IServiceManager) PentahoSystem.get(IServiceManager.class, PentahoSessionHolder.getSession()); try {/* w w w. ja va 2 s.c o m*/ sessionBean = (SessionServlet) serviceManager.getServiceBean("gwt", "session.rpc"); //$NON-NLS-1$ queryBean = (QueryServlet) serviceManager.getServiceBean("gwt", "query.rpc"); //$NON-NLS-1$ discoveryBean = (DiscoveryServlet) serviceManager.getServiceBean("gwt", "discovery.rpc"); //$NON-NLS-1$ platformBean = (PlatformServlet) serviceManager.getServiceBean("gwt", "platform.rpc"); //$NON-NLS-1$ final IPluginManager pluginManager = (IPluginManager) PentahoSystem.get(IPluginManager.class, PentahoSessionHolder.getSession()); final PluginClassLoader pluginClassloader = (PluginClassLoader) pluginManager .getClassLoader(PAT_PLUGIN_NAME); final String hibernateConfigurationFile = PentahoSystem .getSystemSetting("hibernate/hibernate-settings.xml", "settings/config-file", null); //$NON-NLS-1$ final String pentahoHibConfigPath = PentahoSystem.getApplicationContext() .getSolutionPath(hibernateConfigurationFile); if (pluginClassloader == null) throw new ServiceException(Messages.getString("LifeCycleListener.NoPluginClassloader")); //$NON-NLS-1$ Thread.currentThread().setContextClassLoader(pluginClassloader); final URL contextUrl = pluginClassloader.getResource(PAT_APP_CONTEXT); final URL patHibConfigUrl = pluginClassloader.getResource(PAT_HIBERNATE_CONFIG); final URL patPluginPropertiesUrl = pluginClassloader.getResource(PAT_PLUGIN_PROPERTIES); if (patHibConfigUrl == null) throw new ServiceException("File not found: PAT Hibernate Config : " + PAT_HIBERNATE_CONFIG); else LOG.debug(PAT_PLUGIN_NAME + ": PAT Hibernate Config:" + patHibConfigUrl.toString()); if (patPluginPropertiesUrl == null) throw new ServiceException("File not found: PAT Plugin properties : " + PAT_PLUGIN_PROPERTIES); else LOG.debug(PAT_PLUGIN_NAME + ": PAT Plugin Properties:" + patPluginPropertiesUrl.toString()); if (contextUrl != null) { String appContextUrl = contextUrl.toString(); final ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( new String[] { appContextUrl }, false); applicationContext.setClassLoader(pluginClassloader); applicationContext.setConfigLocation(appContextUrl); applicationContext.setAllowBeanDefinitionOverriding(true); final Configuration pentahoHibConfig = new Configuration(); pentahoHibConfig.configure(new File(pentahoHibConfigPath)); final AnnotationConfiguration patHibConfig = new AnnotationConfiguration(); patHibConfig.configure(patHibConfigUrl); Properties properties = new Properties(); properties.load(pluginClassloader.getResourceAsStream(PAT_PLUGIN_PROPERTIES)); String hibernateDialectCfg = (String) properties.get("pat.plugin.datasource.hibernate.dialect"); String hibernateDialect = null; if (StringUtils.isNotBlank(hibernateDialectCfg)) { if (hibernateDialectCfg.equals("auto")) { hibernateDialect = pentahoHibConfig.getProperty("dialect"); } else { hibernateDialect = hibernateDialectCfg; } } if (StringUtils.isNotBlank(hibernateDialect)) { patHibConfig.setProperty("hibernate.dialect", hibernateDialect); LOG.info(PAT_PLUGIN_NAME + " : using hibernate dialect: " + hibernateDialect); } String dataSourceType = (String) properties.get("pat.plugin.datasource.type"); String datasourceResource = null; if (StringUtils.isNotEmpty(dataSourceType) && dataSourceType.equals("jdbc")) { datasourceResource = PAT_DATASOURCE_JDBC; LOG.info(PAT_PLUGIN_NAME + " : using JDBC connection"); } if (StringUtils.isNotEmpty(dataSourceType) && dataSourceType.equals("jndi")) { datasourceResource = PAT_DATASOURCE_JNDI; LOG.info(PAT_PLUGIN_NAME + " : using JNDI : " + (String) properties.get("jndi.name")); } XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource(datasourceResource)); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.setLocation(new ClassPathResource(PAT_PLUGIN_PROPERTIES)); cfg.postProcessBeanFactory(factory); XmlBeanFactory bfSession = new XmlBeanFactory(new ClassPathResource(PAT_SESSIONFACTORY), factory); PropertyPlaceholderConfigurer cfgSession = new PropertyPlaceholderConfigurer(); cfgSession.setProperties(patHibConfig.getProperties()); cfgSession.postProcessBeanFactory(bfSession); ClassPathXmlApplicationContext tmpCtxt = new ClassPathXmlApplicationContext(); tmpCtxt.refresh(); DefaultListableBeanFactory tmpBf = (DefaultListableBeanFactory) tmpCtxt.getBeanFactory(); tmpBf.setParentBeanFactory(bfSession); applicationContext.setClassLoader(pluginClassloader); applicationContext.setParent(tmpCtxt); applicationContext.refresh(); sessionBean.setStandalone(true); SessionServlet.setApplicationContext(applicationContext); sessionBean.init(); queryBean.setStandalone(true); QueryServlet.setApplicationContext(applicationContext); queryBean.init(); discoveryBean.setStandalone(true); DiscoveryServlet.setApplicationContext(applicationContext); discoveryBean.init(); platformBean.setStandalone(true); PlatformServlet.setApplicationContext(applicationContext); platformBean.init(); injectPentahoXmlaUrl(); } else { throw new Exception(Messages.getString("LifeCycleListener.AppContextNotFound")); } } catch (ServiceException e1) { LOG.error(e1.getMessage(), e1); } catch (ServletException e) { LOG.error(e.getMessage(), e); } catch (Exception e) { LOG.error(e.getMessage(), e); } finally { // reset the classloader of the current thread if (origContextClassloader != null) { Thread.currentThread().setContextClassLoader(origContextClassloader); } } }
From source file:net.sourceforge.vulcan.spring.SpringPluginManagerTest.java
public void testPluginAppCtxGetsParentPropertyPlaceholder() throws Exception { final PropertyResourceConfigurer cfgr = new PropertyPlaceholderConfigurer(); final StaticApplicationContext ctx = new StaticApplicationContext(); ctx.getBeanFactory().registerSingleton("foo", cfgr); ctx.refresh();/*from w w w . j a v a 2s.co m*/ mgr.setApplicationContext(ctx); expect(store.getPluginConfigs()).andReturn(new PluginMetaDataDto[] { createFakePluginConfig(true) }); expert.registerPlugin((ClassLoader) anyObject(), (String) anyObject()); replay(); mgr.init(); verify(); assertTrue("should contain cfgr", mgr.plugins.get("1").context.getBeanFactoryPostProcessors().contains(cfgr)); }
From source file:org.nebulaframework.util.spring.NebulaApplicationContext.java
/** * Create a new NebulaApplicationContext using the XML file given and * configures the context using the specified Property File. * //ww w . j av a 2 s . c om * @param configLocation * resource location * @param propsLocation * property file location * @throws BeansException * if context creation failed */ public NebulaApplicationContext(String configLocation, String propsLocation) throws BeansException, IOException { // Load Properties Properties props = new Properties(); FileInputStream fin = new FileInputStream(propsLocation); props.load(fin); fin.close(); // Create Context PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); configurer.setProperties(props); this.addBeanFactoryPostProcessor(configurer); this.setConfigLocation(configLocation); this.refresh(); this.start(); }
From source file:org.rivetlogic.export.components.AbstractXMLProcessor.java
private void initialize() throws AuthenticationFailure, CmaRuntimeException, IOException { if (ticket == null) { if (beanFactory == null) { PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); AbstractApplicationContext context = new ClassPathXmlApplicationContext("application-context.xml"); Resource resource = context.getResource("classpath:core/cma-cfg.properties"); Properties properties = new Properties(); properties.load(resource.getInputStream()); configurer.setProperties(properties); context.addBeanFactoryPostProcessor(configurer); context.refresh();/*from w w w . ja va2 s . c o m*/ beanFactory = context.getBeanFactory(); } authService = (AuthenticationService) beanFactory.getBean("authenticationService", AuthenticationServiceImpl.class); ticket = authService.authenticate(cmaUrl, cmaUsername, cmaPassword.toCharArray()); nodeService = (NodeService) beanFactory.getBean("nodeService", NodeServiceImpl.class); searchService = (SearchService) beanFactory.getBean("searchService", SearchServiceImpl.class); contentService = (ContentServiceImpl) beanFactory.getBean("contentService", ContentServiceImpl.class); } try { authService.validate(ticket); } catch (InvalidTicketException e) { logger.debug("ticket invalid, getting a new one."); ticket = authService.authenticate(cmaUrl, cmaUsername, cmaPassword.toCharArray()); } }