List of usage examples for org.springframework.context.support GenericApplicationContext GenericApplicationContext
public GenericApplicationContext()
From source file:com.lewisd.maven.lint.plugin.CheckMojo.java
private void initializeConfig() throws DependencyResolutionRequiredException, IOException { @SuppressWarnings("rawtypes") List testClasspathElements = project.getTestClasspathElements(); URL[] testUrls = new URL[testClasspathElements.size()]; for (int i = 0; i < testClasspathElements.size(); i++) { String element = (String) testClasspathElements.get(i); testUrls[i] = new File(element).toURI().toURL(); }// w ww.j a v a 2 s . c o m classLoader = new URLClassLoader(testUrls, Thread.currentThread().getContextClassLoader()); applicationContext = new GenericApplicationContext(); ClassPathResource classPathResource = new ClassPathResource(configLocation, classLoader); XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(applicationContext); xmlBeanDefinitionReader.loadBeanDefinitions(classPathResource); applicationContext.getBeanFactory().registerSingleton("log", getLog()); applicationContext.refresh(); }
From source file:com.jaspersoft.jasperserver.export.BaseExportImportCommand.java
protected ConfigurableApplicationContext createSpringContext(Parameters exportParameters, String resourceFileName) throws IOException { GenericApplicationContext ctx = new GenericApplicationContext(); XmlBeanDefinitionReader configReader = new XmlBeanDefinitionReader(ctx); Resource[] resources = ctx.getResources(resourceFileName); commandOut.info("First resource path:" + resources[0].getFile().getAbsolutePath()); Arrays.sort(resources, new ResourceComparator()); commandOut.info("Started to load resources"); for (Resource resource : resources) { commandOut.info("Resource name: " + resource.getFilename()); configReader.loadBeanDefinitions(resource); }/* w w w.ja va 2s . c om*/ ctx.refresh(); return ctx; }
From source file:org.jboss.arquillian.spring.integration.client.ClientApplicationContextLifecycleHandlerTestCase.java
/** * <p>Sets up the test environment.</p> * * @throws Exception if any error occurs *///w w w . j av a 2s. com @Before public void setUp() throws Exception { testClass = new TestClass(TEST_OBJECT.getClass()); testMethod = TEST_OBJECT.getClass().getMethod("testMethod"); instance = new ClientApplicationContextLifecycleHandler(); supportedApplicationContextProducer = mock(ClientApplicationContextProducer.class); when(supportedApplicationContextProducer.supports(any(TestClass.class))).thenReturn(true); when(supportedApplicationContextProducer.createApplicationContext(any(TestClass.class))).thenReturn( new ClientTestScopeApplicationContext(new GenericApplicationContext(), testClass, true)); notSupportedApplicationContextProducer = mock(ClientApplicationContextProducer.class); when(notSupportedApplicationContextProducer.supports(any(TestClass.class))).thenReturn(false); applicationContextDestroyer = mock(ApplicationContextDestroyer.class); mockApplicationContextCreatedEvent = mock(Event.class); TestReflectionHelper.setFieldValue(instance, "applicationContextEvent", mockApplicationContextCreatedEvent); }
From source file:org.jboss.arquillian.spring.integration.container.ContainerApplicationContextLifecycleHandlerTestCase.java
/** * <p>Sets up the test environment.</p> * * @throws Exception if any error occurs *//* w ww . jav a2s. c om*/ @Before public void setUp() throws Exception { testClass = new TestClass(TEST_OBJECT.getClass()); testMethod = TEST_OBJECT.getClass().getMethod("testMethod"); instance = new ContainerApplicationContextLifecycleHandler(); supportedApplicationContextProducer = mock(RemoteApplicationContextProducer.class); when(supportedApplicationContextProducer.supports(any(TestClass.class))).thenReturn(true); when(supportedApplicationContextProducer.createApplicationContext(any(TestClass.class))).thenReturn( new RemoteTestScopeApplicationContext(new GenericApplicationContext(), testClass, true)); notSupportedApplicationContextProducer = mock(RemoteApplicationContextProducer.class); when(notSupportedApplicationContextProducer.supports(any(TestClass.class))).thenReturn(false); applicationContextDestroyer = mock(ApplicationContextDestroyer.class); mockApplicationContextCreatedEvent = mock(Event.class); TestReflectionHelper.setFieldValue(instance, "applicationContextEvent", mockApplicationContextCreatedEvent); }
From source file:org.jboss.arquillian.container.spring.embedded.SpringEmbeddedApplicationContextLifeCycleHandlerTestCase.java
/** * <p>Sets up the test environment.</p> * * @throws Exception if any error occurs *///from ww w .j av a 2s . com @Before public void setUp() throws Exception { testClass = new TestClass(TEST_OBJECT.getClass()); testMethod = TEST_OBJECT.getClass().getMethod("testMethod"); instance = new SpringEmbeddedApplicationContextLifeCycleHandler(); supportedApplicationContextProducer = mock(RemoteApplicationContextProducer.class); when(supportedApplicationContextProducer.supports(any(TestClass.class))).thenReturn(true); when(supportedApplicationContextProducer.createApplicationContext(any(TestClass.class))).thenReturn( new RemoteTestScopeApplicationContext(new GenericApplicationContext(), testClass, true)); notSupportedApplicationContextProducer = mock(RemoteApplicationContextProducer.class); when(notSupportedApplicationContextProducer.supports(any(TestClass.class))).thenReturn(false); applicationContextDestroyer = mock(ApplicationContextDestroyer.class); mockApplicationContextCreatedEvent = mock(Event.class); TestReflectionHelper.setFieldValue(instance, "applicationContextEvent", mockApplicationContextCreatedEvent); }
From source file:com.github.exper0.efilecopier.ftp.DynamicFtpChannelResolver.java
private AbstractApplicationContext getContext(ReportSettings settings) { final String key = String.format("%s:%d", settings.getHost(), settings.getPort()); AbstractApplicationContext context = roots.get(key); if (context == null) { context = new GenericApplicationContext(); DefaultFtpSessionFactory factory = new DefaultFtpSessionFactory(); factory.setUsername(settings.getUser()); factory.setPassword(settings.getPassword()); factory.setHost(settings.getHost()); factory.setPort(settings.getPort()); context.getBeanFactory().registerSingleton("session.factory", factory); context.refresh();//from w ww . ja v a 2 s .c om } return context; }
From source file:au.com.identityconcepts.shibboleth.test.TestCaseBase.java
/** * Creates a Spring context from the given resources. * /*from w ww. j ava2 s .c o m*/ * @param configs context configuration resources * * @return the created context * * @throws ResourceException thrown if there is a problem reading the configuration resources */ protected ApplicationContext createSpringContext(List<Resource> configs) throws ResourceException { GenericApplicationContext gContext = new GenericApplicationContext(); SpringConfigurationUtils.populateRegistry(gContext, configs); gContext.refresh(); return gContext; }
From source file:com.paxxis.cornerstone.messaging.service.shell.ServiceShell.java
private void doDatabaseUpdate(String[] inputs) { GenericApplicationContext ctx = new GenericApplicationContext(); ctx.registerShutdownHook();/*from ww w . j a va2s . c o m*/ ctx.refresh(); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx); xmlReader.loadBeanDefinitions(new FileSystemResource(inputs[0])); DatabaseUpdater updater = ctx.getBean(DatabaseUpdater.class); String target = null; if (inputs.length == 3) { target = inputs[2]; } updater.update(inputs[1], target); ctx.close(); }
From source file:org.springframework.cloud.aws.context.config.xml.ContextCredentialsBeanDefinitionParserTest.java
@Test public void parseBean_withProfileCredentialsProviderAndProfileFile_createProfileCredentialsProvider() throws IOException { GenericApplicationContext applicationContext = new GenericApplicationContext(); Map<String, Object> secretAndAccessKeyMap = new HashMap<>(); secretAndAccessKeyMap.put("profilePath", new ClassPathResource(getClass().getSimpleName() + "-profile", getClass()).getFile() .getAbsolutePath()); applicationContext.getEnvironment().getPropertySources() .addLast(new MapPropertySource("test", secretAndAccessKeyMap)); PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer(); configurer.setPropertySources(applicationContext.getEnvironment().getPropertySources()); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(applicationContext); reader.loadBeanDefinitions(new ClassPathResource( getClass().getSimpleName() + "-profileCredentialsProviderWithFile.xml", getClass())); applicationContext.refresh();/*from w w w . j a va 2s .c o m*/ AWSCredentialsProvider provider = applicationContext.getBean( AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, AWSCredentialsProvider.class); assertNotNull(provider); assertEquals("testAccessKey", provider.getCredentials().getAWSAccessKeyId()); assertEquals("testSecretKey", provider.getCredentials().getAWSSecretKey()); }
From source file:edu.internet2.middleware.shibboleth.common.attribute.AttributeAuthorityCLI.java
/** * Loads the configuration files into a Spring application context. * /*from w w w .ja va 2 s . com*/ * @param configDir directory containing spring configuration files * @param springExts colon-separated list of spring extension files * * @return loaded application context * * @throws java.io.IOException throw if there is an error loading the configuration files * @throws ResourceException if there is an error loading the configuration files */ private static ApplicationContext loadConfigurations(String configDir, String springExts) throws IOException, ResourceException { File configDirectory; if (configDir != null) { configDirectory = new File(configDir); } else { configDirectory = new File(System.getenv("IDP_HOME") + "/conf"); } if (!configDirectory.exists() || !configDirectory.isDirectory() || !configDirectory.canRead()) { errorAndExit("Configuration directory " + configDir + " does not exist, is not a directory, or is not readable", null); } loadLoggingConfiguration(configDirectory.getAbsolutePath()); File config; List<String> configFiles = new ArrayList<String>(); List<Resource> configs = new ArrayList<Resource>(); // Add built-in files. for (String i : aacliConfigs) { configFiles.add(i); } // Add extensions, if any. if (springExts != null && !springExts.isEmpty()) { String[] extFiles = springExts.split(":"); for (String extFile : extFiles) { configFiles.add(extFile); } } for (String cfile : configFiles) { config = new File(configDirectory.getPath() + File.separator + cfile); if (config.isDirectory() || !config.canRead()) { errorAndExit( "Configuration file " + config.getAbsolutePath() + " is a directory or is not readable", null); } configs.add(new FilesystemResource(config.getPath())); } GenericApplicationContext gContext = new GenericApplicationContext(); SpringConfigurationUtils.populateRegistry(gContext, configs); gContext.refresh(); return gContext; }