/** * Set the config locations for this application context in init-param style, * i.e. with distinct locations separated by commas, semicolons or whitespace. * <p>If not set, the implementation may use a default as appropriate. */ public void setConfigLocation(String location) { setConfigLocations(StringUtils.tokenizeToStringArray(location, CONFIG_LOCATION_DELIMITERS)); }
@Override public String[] getConfigLocations() { return super.getConfigLocations(); }
public ExtendsSpringBeanContainer(ExtendsSpringBeanContainer parent, ClassLoader loader, Class<? extends AbstractRefreshableConfigApplicationContext> clazz) { if (inited == true) return; inited = true; try { applicationContext = clazz.newInstance(); } catch (Exception e) { throw new RuntimeException(e); } applicationContext.setParent(parent.getBeanContainerPrototype()); applicationContext.setAllowBeanDefinitionOverriding(true); applicationContext.setClassLoader(loader); applicationContext.refresh(); }
this.applicationContext.getResources(configurationResource); checkedConfigurationResources.add(configurationResource); } catch (IOException e) { this.applicationContext.setConfigLocations(checkedConfigurationResources.toArray(new String [0])); ppc.setSystemPropertiesMode(configuration.getInt(SYSTEM_PROPERTIES_MODE, PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_FALLBACK)); ppc.setProperties(initProps); this.applicationContext.addBeanFactoryPostProcessor(ppc); this.applicationContext.refresh();
public void refresh() { applicationContext.setConfigLocations(listToArray(configs)); applicationContext.refresh(); }
AbstractRefreshableConfigApplicationContext ctx = new ClassPathXmlApplicationContext(); // init empty Properties ftpSessionProps = new Properties(); ftpSessionProps.setProperty("user", "first"); StandardEnvironment env = new StandardEnvironment(); env.getPropertySources().addLast(new PropertiesPropertySource("pops", ftpSessionProps)); ctx.setEnvironment(env); ctx.setConfigLocation("classpath:main.xml"); // set the config here ctx.refresh(); ctx.start();
@Override public void initialize(AbstractRefreshableConfigApplicationContext ctx) { ctx.setAllowBeanDefinitionOverriding(false); ConfigurableEnvironment env = ctx.getEnvironment(); Set<String> aps = new LinkedHashSet<>(); Collections.addAll(aps, env.getActiveProfiles()); Collections.addAll(aps, testConfig ? Constants.PROFILES_TEST : Constants.PROFILES_PROD); env.getPropertySources().addLast(new LabelPropertySource()); env.getPropertySources().addLast(new DomainPropertySource(ctx)); env.setDefaultProfiles(Constants.PROFILE_ROOT_DEFAULT); ctx.setConfigLocations(Constants.DEFAULT_LOCATIONS); env.setActiveProfiles(aps.toArray(new String[aps.size()])); }
/** * 当调用无参构造函数时,会默认初始化为FileSystemXmlApplicationContext实例 * 可通过此方法改变ApplicationContext的类型 * * @param clazz */ public void setApplicationType(Class<? extends AbstractRefreshableConfigApplicationContext> clazz) { if (initedByDefault == false) { throw new RuntimeException("该方法仅允许执行无参构造函数时调用"); } if (applicationContext != null) { applicationContext.destroy(); } try { applicationContext = clazz.newInstance(); } catch (Exception e) { throw new RuntimeException(e); } applicationContext.setAllowBeanDefinitionOverriding(true); applicationContext.refresh(); }
public ExtendsSpringBeanContainer() { if (inited == true) return; inited = true; initedByDefault = true; applicationContext = new FileSystemXmlApplicationContext(); applicationContext.setAllowBeanDefinitionOverriding(true); applicationContext.refresh(); }
public <T> T getComponent(String name) { T bean = null; try { bean = (T) this.applicationContext.getBean(name); } catch (Exception ignore) { } return bean; }
@Override public void close() { if (isRunning()) { super.close(); applicationModel.close(); } }
public void start() { this.applicationContext.start(); }
/** * Resolve the given path, replacing placeholders with corresponding * environment property values if necessary. Applied to config locations. * @param path the original file path * @return the resolved file path * @see org.springframework.core.env.Environment#resolveRequiredPlaceholders(String) */ protected String resolvePath(String path) { return getEnvironment().resolveRequiredPlaceholders(path); }
public <T> T getBean(Class<T> clazz) { String[] beanNames = applicationContext.getBeanNamesForType(clazz); if (beanNames.length == 1) { return (T) applicationContext.getBean(beanNames[0]); } else if (beanNames.length == 0 && parent != null) { return parent.getBean(clazz); } else { throw new NoSuchBeanDefinitionException(clazz, "expected single bean but found " + beanNames.length + ": " + StringUtils.arrayToCommaDelimitedString(beanNames)); } }
@Override protected void customizeBeanFactory(DefaultListableBeanFactory beanFactory) { super.customizeBeanFactory(beanFactory); new SpringMuleContextServiceConfigurator(muleContext, applicationModel.getConfigurationProperties(), artifactType, optionalObjectsController, beanFactory, componentLocator, serviceDiscoverer, originalRegistry, resourceLocator).createArtifactServices(); originalRegistry = null; }
/** * Return an array of resource locations, referring to the XML bean definition * files that this context should be built with. Can also include location * patterns, which will get resolved via a ResourcePatternResolver. * <p>The default implementation returns {@code null}. Subclasses can override * this to provide a set of resource locations to load bean definitions from. * @return an array of resource locations, or {@code null} if none * @see #getResources * @see #getResourcePatternResolver */ @Nullable protected String[] getConfigLocations() { return (this.configLocations != null ? this.configLocations : getDefaultConfigLocations()); }
public ExtendsSpringBeanContainer(ExtendsSpringBeanContainer parent, List<FileObject> files, ClassLoader loader, Class<? extends AbstractRefreshableConfigApplicationContext> clazz) { if (inited == true) return; inited = true; List<String> configLocations = new ArrayList<String>(); for (FileObject fileObject : files) { String urlString = fileObject.getURL().toString(); if (!configLocations.contains(urlString)) { configLocations.add(urlString); LOGGER.logMessage(LogLevel.INFO, "添加Spring配置文件:{urlString}", urlString); } } try { applicationContext = clazz.newInstance(); } catch (Exception e) { throw new RuntimeException(e); } applicationContext.setConfigLocations(listToArray(configLocations)); applicationContext.setParent(parent.getBeanContainerPrototype()); applicationContext.setAllowBeanDefinitionOverriding(true); applicationContext.setClassLoader(loader); applicationContext.refresh(); // initNoBeanCaseInfo(); }
this.applicationContext.getResources(configurationResource); checkedConfigurationResources.add(configurationResource); } catch (IOException e) { this.applicationContext.setConfigLocations(checkedConfigurationResources.toArray(new String [0])); ppc.setSystemPropertiesMode(configuration.getInt(SYSTEM_PROPERTIES_MODE, PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_FALLBACK)); ppc.setProperties(initProps); this.applicationContext.addBeanFactoryPostProcessor(ppc); } else if (getContainerConfiguration() != null) { Properties initProps = getContainerConfiguration().toProperties(); ppc.setSystemPropertiesMode(getContainerConfiguration().getInt(SYSTEM_PROPERTIES_MODE, PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_FALLBACK)); ppc.setProperties(initProps); this.applicationContext.addBeanFactoryPostProcessor(ppc); this.applicationContext.refresh();
public void initialize() { applicationContext = new DefaultComponentManagerApplicationContext(componentManager.getContainerConfiguration(), parentApplicationContext); if (componentManager != null && applicationContext instanceof ComponentManagerAware) { ((ComponentManagerAware) applicationContext).setComponentManager(componentManager); } String [] checkedConfigurationResources = ApplicationContextUtils.getCheckedLocationPatterns(applicationContext, moduleDefinition.getConfigLocations()); if (ArrayUtils.isEmpty(checkedConfigurationResources)) { log.warn("There's no valid component configuration for addon module, '{}'.", name); } applicationContext.setConfigLocations(checkedConfigurationResources); applicationContext.refresh(); for (ModuleInstance moduleInstance : getModuleInstances()) { if (componentManager != null && moduleInstance instanceof ComponentManagerAware) { ((ComponentManagerAware) moduleInstance).setComponentManager(componentManager); } if (componentManager != null && moduleInstance instanceof ApplicationContextAware) { ((ApplicationContextAware) moduleInstance).setApplicationContext(applicationContext); } moduleInstance.initialize(); } }