public ExtendsSpringBeanContainer() { if (inited == true) return; inited = true; initedByDefault = true; applicationContext = new FileSystemXmlApplicationContext(); applicationContext.setAllowBeanDefinitionOverriding(true); applicationContext.refresh(); }
/** * 当调用无参构造函数时,会默认初始化为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(); }
@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()])); }
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(); }
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(); }