public static void main(String[] args) { List<String> languages = Arrays.asList(new String[]{"groovy","ruby","javascript","python"}); if (args.length != 1) { usage(); } String lang = args[0]; if (!StringUtils.hasText(lang)){ usage(); } lang = lang.toLowerCase(); if (!languages.contains(lang)){ usage(); } /* * Create an application context and set the active profile to configure the * corresponding scripting implementation */ ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(); ctx.getEnvironment().setActiveProfiles(lang); ctx.setConfigLocation("/META-INF/spring/integration/cafeDemo.xml"); ctx.refresh(); }
MutablePropertySources sources = ctx.getEnvironment().getPropertySources(); for (String propertyFile : appPropertiesFiles) { try {
@Test public void testBeanFactoryProfileRespected() { GenericApplicationContextFactory factory = new GenericApplicationContextFactory( new ClassPathResource(ClassUtils.addResourcePathToPackagePath(getClass(), "profiles.xml"))); @SuppressWarnings("resource") ClassPathXmlApplicationContext parentContext = new ClassPathXmlApplicationContext(ClassUtils.addResourcePathToPackagePath( getClass(), "parent-context.xml")); parentContext.getEnvironment().setActiveProfiles("preferred"); factory.setApplicationContext(parentContext); @SuppressWarnings("resource") ConfigurableApplicationContext context = factory.createApplicationContext(); assertEquals("test-job", context.getBeanNamesForType(Job.class)[0]); assertEquals("spam", context.getBean("test-job", Job.class).getName()); }
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"your_config.xml"}, false); // all sorts of constructors, many options for finding the resource ResourcePropertySource properties = new ResourcePropertySource("path/to/my.properties"); context.getEnvironment().getPropertySources().addLast(properties); context.refresh();
//load the appcontext with refresh value as false ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "classpath:appcontext.xml" }, false); //add the props file context.getEnvironment().getPropertySources().addFirst(new ResourcePropertySource("classpath:app.properties")); //refresh the context context.refresh();
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(); ctx.setConfigLocation("applicationContext.xml"); ctx.getEnvironment().getPropertySources().addLast(new FooPropertySource()); ctx.refresh();
ctx.getEnvironment().getPropertySources().addFirst(pps); String contextPath = System.getProperty(pn_config_path); ctx.setConfigLocation("file:" + contextPath + "/spring/admin-schema-context.xml");
ctx.getEnvironment().getPropertySources().addFirst(pps); String contextPath = System.getProperty(pn_config_path); ctx.setConfigLocation("file:" + contextPath + "/spring/cache-xqj-context.xml");
appCtx.getEnvironment().setActiveProfiles(sqldbType.name());