List of usage examples for org.springframework.beans.factory.config PropertyOverrideConfigurer PropertyOverrideConfigurer
PropertyOverrideConfigurer
From source file:se.ivankrizsan.messagecowboy.ProductionPropertyOverrides.java
/** * Overrides properties configured on beans. *///from w w w . j a v a 2 s .com @Bean() @Lazy(false) @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON) public static BeanFactoryPostProcessor propertyOverrideConfigurer() { PropertyOverrideConfigurer theOverrideConfigurer = new PropertyOverrideConfigurer(); final Properties thePropertiesHolder = new Properties(); /* Task refresh interval. */ thePropertiesHolder.put("starterService.taskReschedulingCronExpression", "0/20 * * * * ?"); /* Transport service configuration refresh interval. */ thePropertiesHolder.put("starterService.transportServiceConfigurationRefreshCronExpression", "0/30 * * * * ?"); /* Task execution status reports cleanup interval. */ thePropertiesHolder.put("starterService.taskExecutionStatusCleanupCronExpression", "0/30 0/15 * * * ?"); theOverrideConfigurer.setProperties(thePropertiesHolder); theOverrideConfigurer.setIgnoreInvalidKeys(false); theOverrideConfigurer.setIgnoreResourceNotFound(false); theOverrideConfigurer.setOrder(0); return theOverrideConfigurer; }
From source file:se.ivankrizsan.messagecowboy.integrationtest.taskexecutionstatuscleanup.TaskExecutionStatusCleanupTestConfiguration.java
/** * Overrides properties configured on beans. *///from w w w .j av a2 s . com @Bean() @Lazy(false) @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON) public static BeanFactoryPostProcessor propertyOverrideConfigurer() { PropertyOverrideConfigurer theOverrideConfigurer = new PropertyOverrideConfigurer(); final Properties thePropertiesHolder = new Properties(); /* Task refresh interval. */ thePropertiesHolder.put("starterService.taskReschedulingCronExpression", "* 4/30 * * * ?"); /* Transport service configuration refresh interval. */ thePropertiesHolder.put("starterService.transportServiceConfigurationRefreshCronExpression", "* 5/30 * * * ?"); /* Task execution status reports cleanup interval. */ thePropertiesHolder.put("starterService.taskExecutionStatusCleanupCronExpression", "0/5 * * * * ?"); theOverrideConfigurer.setProperties(thePropertiesHolder); theOverrideConfigurer.setIgnoreInvalidKeys(false); theOverrideConfigurer.setIgnoreResourceNotFound(false); theOverrideConfigurer.setOrder(0); return theOverrideConfigurer; }
From source file:net.sourceforge.jabm.init.RandomVariateInitialiser.java
@Override public Simulation initialise(SimulationController simulationController) { this.eventScheduler = simulationController; java.util.Properties variateBindings = new java.util.Properties(); for (String variable : expressionBindings.keySet()) { Number value = evaluate(expressionBindings.get(variable), variateBindings); variateBindings.put(variable, value + ""); logger.info(variable + " = " + value); fireEvent(variable, value);/*from ww w .ja v a 2s. co m*/ } PropertyOverrideConfigurer configurer = new PropertyOverrideConfigurer(); configurer.setProperties(variateBindings); configurer.setLocalOverride(true); configurer.postProcessBeanFactory( (ConfigurableListableBeanFactory) ((SpringSimulationController) simulationController) .getBeanFactory()); return super.initialise(simulationController); }
From source file:com.kurento.kmf.spring.KurentoApplicationContextUtils.java
/** * This class returns the Spring KurentoApplicationContext, which is the * parent context for all specific Kurento Servlet contexts. In case a * pre-exiting Spring root WebApplicationContext if found, the returned * KurentoApplicationContext will be made child of this root context. When * necessary, this method creates the KurentoApplicationContext, so it * should never return null.//from w ww . j av a 2 s. c o m * * This method MUST NOT be called in ServletContextListeners, given that at * that stage there might not be information about the presence of a root * Spring root WebApplicationConext. * * @param ctx * @return * */ public static AnnotationConfigApplicationContext createKurentoApplicationContext(ServletContext ctx) { Assert.notNull(ctx, "Cannot recover KurentoApplicationContext from a null ServletContext"); Assert.isNull(kurentoApplicationContextInternalReference, "Pre-existing Kurento ApplicationContext found. Cannot create a new instance."); kurentoApplicationContextInternalReference = new AnnotationConfigApplicationContext(); // Add or remove packages when required kurentoApplicationContextInternalReference.scan("com.kurento.kmf"); // Recover root WebApplicationContext context just in case // application developer is using Spring WebApplicationContext rootContext = WebApplicationContextUtils.getWebApplicationContext(ctx); if (rootContext != null) { kurentoApplicationContextInternalReference.setParent(rootContext); } final String jbossServerConfigDir = System.getProperty("jboss.server.config.dir"); final String kurentoPropertiesDir = System.getProperty("kurento.properties.dir"); final String kurentoProperties = "/kurento.properties"; InputStream inputStream = null; try { if (jbossServerConfigDir != null && new File(jbossServerConfigDir + kurentoProperties).exists()) { // First, look for JVM argument "jboss.server.config.dir" inputStream = new FileInputStream(jbossServerConfigDir + kurentoProperties); log.info("Found custom properties in 'jboss.server.config.dir': " + jbossServerConfigDir); } else if (kurentoPropertiesDir != null && new File(kurentoPropertiesDir + kurentoProperties).exists()) { // Second, look for JVM argument "kurento.properties.dir" log.info("Found custom properties in 'kurento.properties.dir': " + kurentoPropertiesDir); inputStream = new FileInputStream(kurentoPropertiesDir + kurentoProperties); } else { // Third, look for properties in Servlet Context ServletContextResource servletContextResource = new ServletContextResource(ctx, "/WEB-INF" + kurentoProperties); if (servletContextResource.exists()) { log.info("Found custom properties in Servlet Context: /WEB-INF" + kurentoProperties); inputStream = servletContextResource.getInputStream(); } } if (inputStream != null) { Properties properties = new Properties(); properties.load(inputStream); PropertyOverrideConfigurer propertyOverrideConfigurer = new PropertyOverrideConfigurer(); propertyOverrideConfigurer.setProperties(properties); kurentoApplicationContextInternalReference.addBeanFactoryPostProcessor(propertyOverrideConfigurer); inputStream.close(); } } catch (IOException e) { log.error("Exception loading custom properties", e); throw new RuntimeException(e); } kurentoApplicationContextInternalReference.refresh(); return kurentoApplicationContextInternalReference; }
From source file:org.smigo.config.WebConfiguration.java
@Bean public static PropertyOverrideConfigurer propertyOverrideConfigurer() { return new PropertyOverrideConfigurer(); }
From source file:org.sakaiproject.component.cover.TestComponentManagerContainer.java
/** * create a component manager based on a list of component.xml * @param configPaths a ';' seperated list of xml bean config files * @throws IOException/*from www . j ava2s . co m*/ */ public TestComponentManagerContainer(String configPaths, Properties props) throws IOException { // we assume that all the jars are in the same classloader, so this will // not check for // incorrect bindings and will not fully replicate the tomcat // experience, but is an easier environment // to work within for kernel testing. // For a more complex structure we could use the kernel poms in the repo // to generate the dep list. if (ComponentManager.m_componentManager != null) { log.info("Closing existing Component Manager "); /* try { ComponentManager.m_componentManager.close(); } catch ( Throwable t ) { log.warn("Close Failed with message, safe to ignore "+t.getMessage()); } */ log.info("Closing Complete "); ComponentManager.m_componentManager = null; } log.info("Starting Component Manager with [" + configPaths + "]"); ComponentManager.setLateRefresh(true); componentManager = (SpringCompMgr) ComponentManager.getInstance(); ConfigurableApplicationContext ac = componentManager.getApplicationContext(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); // Supply any additional configuration. if (props != null) { PropertyOverrideConfigurer beanFactoryPostProcessor = new PropertyOverrideConfigurer(); beanFactoryPostProcessor.setBeanNameSeparator("@"); beanFactoryPostProcessor.setProperties(props); ac.addBeanFactoryPostProcessor(beanFactoryPostProcessor); } // we could take the kernel bootstrap from from the classpath in future // rather than from // the filesystem List<Resource> config = new ArrayList<Resource>(); String[] configPath = configPaths.split(";"); for (String p : configPath) { File xml = new File(p); config.add(new FileSystemResource(xml.getCanonicalPath())); } loadComponent(ac, config, classLoader); ac.refresh(); // SAK-20908 - band-aid for TLM sync issues causing tests to fail // This sleep shouldn't be needed but it seems these tests are starting before ThreadLocalManager has finished its startup. try { Thread.sleep(500); // 1/2 second log.debug("Finished starting the component manager"); } catch (InterruptedException e) { log.error("Component manager startup interrupted..."); } }