@Nullable public Object getProperty(String property) { if (containsBean(property)) { return getBean(property); } else if (this.contextWrapper.isReadableProperty(property)) { return this.contextWrapper.getPropertyValue(property); } throw new NoSuchBeanDefinitionException(property); }
/** * Create a new GenericGroovyApplicationContext, loading bean definitions * from the given resource locations and automatically refreshing the context. * @param resourceLocations the resources to load from */ public GenericGroovyApplicationContext(String... resourceLocations) { load(resourceLocations); refresh(); }
public void setProperty(String property, Object newValue) { if (newValue instanceof BeanDefinition) { registerBeanDefinition(property, (BeanDefinition) newValue); } else { this.metaClass.setProperty(this, property, newValue); } }
@Test public void testLoadingMultipleConfigFilesWithRelativeClass() { GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext(); ctx.load(GroovyApplicationContextTests.class, "applicationContext2.groovy", "applicationContext.groovy"); ctx.refresh(); Object framework = ctx.getBean("framework"); assertNotNull("could not find framework bean", framework); assertEquals("Grails", framework); Object company = ctx.getBean("company"); assertNotNull("could not find company bean", company); assertEquals("SpringSource", company); }
@Test public void testLoadingConfigFile() { GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext( "org/springframework/context/groovy/applicationContext.groovy"); Object framework = ctx.getBean("framework"); assertNotNull("could not find framework bean", framework); assertEquals("Grails", framework); }
/** * Load bean definitions from the given Groovy scripts or XML files. * <p>Note that ".xml" files will be parsed as XML content; all other kinds * of resources will be parsed as Groovy scripts. * @param relativeClass class whose package will be used as a prefix when * loading each specified resource name * @param resourceNames relatively-qualified names of resources to load */ public void load(Class<?> relativeClass, String... resourceNames) { Resource[] resources = new Resource[resourceNames.length]; for (int i = 0; i < resourceNames.length; i++) { resources[i] = new ClassPathResource(resourceNames[i], relativeClass); } load(resources); }
/** * Delegates the given environment to underlying {@link GroovyBeanDefinitionReader}. * Should be called before any call to {@code #load}. */ @Override public void setEnvironment(ConfigurableEnvironment environment) { super.setEnvironment(environment); this.reader.setEnvironment(getEnvironment()); }
@Test(expected = BeanDefinitionParsingException.class) public void testConfigFileParsingError() { new GenericGroovyApplicationContext("org/springframework/context/groovy/applicationContext-error.groovy"); }
@Test public void testLoadingMultipleConfigFiles() { GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext( "org/springframework/context/groovy/applicationContext2.groovy", "org/springframework/context/groovy/applicationContext.groovy"); Object framework = ctx.getBean("framework"); assertNotNull("could not find framework bean", framework); assertEquals("Grails", framework); Object company = ctx.getBean("company"); assertNotNull("could not find company bean", company); assertEquals("SpringSource", company); }
/** * Load bean definitions from the given Groovy scripts or XML files. * <p>Note that ".xml" files will be parsed as XML content; all other kinds * of resources will be parsed as Groovy scripts. * @param relativeClass class whose package will be used as a prefix when * loading each specified resource name * @param resourceNames relatively-qualified names of resources to load */ public void load(Class<?> relativeClass, String... resourceNames) { Resource[] resources = new Resource[resourceNames.length]; for (int i = 0; i < resourceNames.length; i++) { resources[i] = new ClassPathResource(resourceNames[i], relativeClass); } load(resources); }
/** * Delegates the given environment to underlying {@link GroovyBeanDefinitionReader}. * Should be called before any call to {@code #load}. */ @Override public void setEnvironment(ConfigurableEnvironment environment) { super.setEnvironment(environment); this.reader.setEnvironment(getEnvironment()); }
@Test @SuppressWarnings("resource") public void verifyScriptUsingGenericGroovyApplicationContext() { ApplicationContext ctx = new GenericGroovyApplicationContext(getClass(), "context.groovy"); String foo = ctx.getBean("foo", String.class); assertEquals("Foo", foo); String bar = ctx.getBean("bar", String.class); assertEquals("Bar", bar); Pet pet = ctx.getBean(Pet.class); assertNotNull("pet", pet); assertEquals("Dogbert", pet.getName()); Employee employee = ctx.getBean(Employee.class); assertNotNull("employee", employee); assertEquals("Dilbert", employee.getName()); assertEquals("???", employee.getCompany()); }
@Nullable public Object getProperty(String property) { if (containsBean(property)) { return getBean(property); } else if (this.contextWrapper.isReadableProperty(property)) { return this.contextWrapper.getPropertyValue(property); } throw new NoSuchBeanDefinitionException(property); }
/** * Load bean definitions from the given Groovy scripts or XML files. * <p>Note that ".xml" files will be parsed as XML content; all other kinds * of resources will be parsed as Groovy scripts. * @param relativeClass class whose package will be used as a prefix when * loading each specified resource name * @param resourceNames relatively-qualified names of resources to load */ public void load(Class<?> relativeClass, String... resourceNames) { Resource[] resources = new Resource[resourceNames.length]; for (int i = 0; i < resourceNames.length; i++) { resources[i] = new ClassPathResource(resourceNames[i], relativeClass); } load(resources); }
public void setProperty(String property, Object newValue) { if (newValue instanceof BeanDefinition) { registerBeanDefinition(property, (BeanDefinition) newValue); } else { this.metaClass.setProperty(this, property, newValue); } }
/** * Delegates the given environment to underlying {@link GroovyBeanDefinitionReader}. * Should be called before any call to {@code #load}. */ @Override public void setEnvironment(ConfigurableEnvironment environment) { super.setEnvironment(environment); this.reader.setEnvironment(getEnvironment()); }
/** * Create a new GenericGroovyApplicationContext, loading bean definitions * from the given resource locations and automatically refreshing the context. * @param relativeClass class whose package will be used as a prefix when * loading each specified resource name * @param resourceNames relatively-qualified names of resources to load */ public GenericGroovyApplicationContext(Class<?> relativeClass, String... resourceNames) { load(relativeClass, resourceNames); refresh(); }
@Nullable public Object getProperty(String property) { if (containsBean(property)) { return getBean(property); } else if (this.contextWrapper.isReadableProperty(property)) { return this.contextWrapper.getPropertyValue(property); } throw new NoSuchBeanDefinitionException(property); }
public void setProperty(String property, Object newValue) { if (newValue instanceof BeanDefinition) { registerBeanDefinition(property, (BeanDefinition) newValue); } else { this.metaClass.setProperty(this, property, newValue); } }