List of usage examples for org.springframework.beans.factory.config PropertyPlaceholderConfigurer setLocation
public void setLocation(Resource location)
From source file:de.pksoftware.springstrap.core.config.RootConfigBase.java
/** * Configure PropertyPlaceholderConfigurer. * @return/*from w w w. ja v a 2 s . c o m*/ */ @Bean public PropertyPlaceholderConfigurer propertyPlaceholderConfigurerBean() { logger.info("Creating PPC Bean..."); PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer(); propertyPlaceholderConfigurer.setLocation(new ClassPathResource(getPropertyFileName())); //propertyPlaceholderConfigurer.setIgnoreResourceNotFound(true); //propertyPlaceholderConfigurer.setIgnoreUnresolvablePlaceholders(true); return propertyPlaceholderConfigurer; //ClassPathResource[] resources = new ClassPathResource[ ] // { new ClassPathResource( getPropertyFileName() ) }; }
From source file:com.baidu.cc.spring.ConfigCenterPropertyExtractorTest.java
/** * test property extractor//from w w w . j av a 2 s . c o m * this test method is ignored due to local environment required. * * @throws Exception throw out all exception to break unit test and mark failed. */ @Ignore @Test public void testPropertyExtractorNoMock() throws Exception { PropertyPlaceholderConfigurer extractor = new PropertyPlaceholderConfigurer(); ClassPathResource cpr = new ClassPathResource("/com/baidu/cc/spring/test.properties"); extractor.setLocation(cpr); ConfigCenterPropertyPlaceholderConfigurer importer; importer = new ConfigCenterPropertyPlaceholderConfigurer(); importer.setCcUser("test1"); importer.setCcPassword("123"); importer.setCcVersion(586); importer.setCcServerUrl("http://localhost:8080/rpc/ExtConfigServerService"); importer.setReadTimeout(5000); //initial importer ConfigCenterPropertyPlaceholderConfigurerTest test = new ConfigCenterPropertyPlaceholderConfigurerTest(); importer.setApplicationContext(test.appContext); DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); importer.postProcessBeanFactory(beanFactory); ConfigCenterPropertyExtractor ccpe = new ConfigCenterPropertyExtractor(); ccpe.setCcVersion(586); ccpe.setExtractor(extractor); ccpe.setImporter(importer); ccpe.afterPropertiesSet(); }
From source file:com.opengamma.component.factory.AbstractSpringComponentFactory.java
/** * Creates the application context./*from w w w . j av a 2 s . c o m*/ * * @param repo the component repository, not null * @return the Spring application context, not null */ protected GenericApplicationContext createApplicationContext(ComponentRepository repo) { Resource springFile = getSpringFile(); try { repo.getLogger().logDebug(" Spring file: " + springFile.getURI()); } catch (Exception ex) { // ignore } DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); GenericApplicationContext appContext = new GenericApplicationContext(beanFactory); PropertyPlaceholderConfigurer properties = new PropertyPlaceholderConfigurer(); properties.setLocation(getPropertiesFile()); XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory); beanDefinitionReader.setValidating(true); beanDefinitionReader.setResourceLoader(appContext); beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(appContext)); beanDefinitionReader.loadBeanDefinitions(springFile); appContext.getBeanFactory().registerSingleton("injectedProperties", properties); appContext.getBeanFactory().registerSingleton("componentRepository", repo); appContext.refresh(); return appContext; }
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 . j av a2 s . c om 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:gov.nih.nci.cagrid.identifiers.service.IdentifiersNAServiceImpl.java
public IdentifiersNAServiceImpl() throws RemoteException { super();/*ww w .j av a 2 s . com*/ try { String naConfigurationFile = getConfiguration().getNaConfigurationFile(); String naProperties = getConfiguration().getNaPropertiesFile(); FileSystemResource naConfResource = new FileSystemResource(naConfigurationFile); FileSystemResource naPropertiesResource = new FileSystemResource(naProperties); XmlBeanFactory factory = new XmlBeanFactory(naConfResource); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.setLocation(naPropertiesResource); cfg.postProcessBeanFactory(factory); this.namingAuthority = (MaintainerNamingAuthority) factory.getBean(NA_BEAN_NAME, MaintainerNamingAuthority.class); } catch (Exception e) { String message = "Problem inititializing NamingAuthority while loading configuration:" + e.getMessage(); LOG.error(message, e); throw new RemoteException(message, e); } }
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();//from w w w . ja v a2 s . c o m 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"); }