org.springframework.beans.factory.config.PropertiesFactoryBean源码实例Demo

类org.springframework.beans.factory.config.PropertiesFactoryBean源码实例Demo

下面列出了org.springframework.beans.factory.config.PropertiesFactoryBean 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Test
public void byTypeAutowireWithPrimaryInParentFactory() throws Exception {
	CountingFactory.reset();
	DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
	parent.getBeanDefinition("props1").setPrimary(true);
	parent.preInstantiateSingletons();
	DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
	RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class);
	robDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
	robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally"));
	child.registerBeanDefinition("rob2", robDef);
	RootBeanDefinition propsDef = new RootBeanDefinition(PropertiesFactoryBean.class);
	propsDef.getPropertyValues().add("properties", "name=props3");
	child.registerBeanDefinition("props3", propsDef);
	TestBean rob = (TestBean) child.getBean("rob2");
	assertEquals("props1", rob.getSomeProperties().getProperty("name"));
	assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
 
@Test
public void byTypeAutowireWithPrimaryOverridingParentFactory() throws Exception {
	CountingFactory.reset();
	DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
	parent.preInstantiateSingletons();
	DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
	RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class);
	robDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
	robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally"));
	child.registerBeanDefinition("rob2", robDef);
	RootBeanDefinition propsDef = new RootBeanDefinition(PropertiesFactoryBean.class);
	propsDef.getPropertyValues().add("properties", "name=props3");
	propsDef.setPrimary(true);
	child.registerBeanDefinition("props3", propsDef);
	TestBean rob = (TestBean) child.getBean("rob2");
	assertEquals("props3", rob.getSomeProperties().getProperty("name"));
	assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
 
@Test
public void byTypeAutowireWithPrimaryInParentAndChild() throws Exception {
	CountingFactory.reset();
	DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
	parent.getBeanDefinition("props1").setPrimary(true);
	parent.preInstantiateSingletons();
	DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
	RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class);
	robDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
	robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally"));
	child.registerBeanDefinition("rob2", robDef);
	RootBeanDefinition propsDef = new RootBeanDefinition(PropertiesFactoryBean.class);
	propsDef.getPropertyValues().add("properties", "name=props3");
	propsDef.setPrimary(true);
	child.registerBeanDefinition("props3", propsDef);
	TestBean rob = (TestBean) child.getBean("rob2");
	assertEquals("props3", rob.getSomeProperties().getProperty("name"));
	assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
 
@Test
public void testExpressionInStringArray() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	BeanExpressionResolver beanExpressionResolver = mock(BeanExpressionResolver.class);
	given(beanExpressionResolver.evaluate(eq("#{foo}"), any(BeanExpressionContext.class)))
			.willReturn("classpath:/org/springframework/beans/factory/xml/util.properties");
	bf.setBeanExpressionResolver(beanExpressionResolver);

	RootBeanDefinition rbd = new RootBeanDefinition(PropertiesFactoryBean.class);
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("locations", new String[]{"#{foo}"});
	rbd.setPropertyValues(pvs);
	bf.registerBeanDefinition("myProperties", rbd);
	Properties properties = (Properties) bf.getBean("myProperties");
	assertEquals("bar", properties.getProperty("foo"));
}
 
源代码5 项目: seppb   文件: QuartzConfiguration.java
@Bean
public Properties quartzProperties() throws IOException {
	PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
	propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
	propertiesFactoryBean.afterPropertiesSet();
	Properties result = propertiesFactoryBean.getObject();

	// 从环境信息中剥离出配置好的环境信息,覆盖默认的配置
	String dsName = result.getProperty("org.quartz.jobStore.dataSource");
	if (StringUtils.isEmpty(dsName)) {
		throw new RuntimeException("quartz配置文件错误,org.quartz.jobStore.dataSource不能为空!");
	}
	result.setProperty("org.quartz.dataSource." + dsName + ".URL", jdbcUrl);
	result.setProperty("org.quartz.dataSource." + dsName + ".user", jdbcUserName);
	result.setProperty("org.quartz.dataSource." + dsName + ".password", jdbcPassword);
	return result;
}
 
源代码6 项目: Project   文件: SpELConfig.java
/**
	* <p>描述:定义bean并加装多个自定义属性文件</p>
	* @param properties
	* @return
	* @author LZC
	 */
	@Bean("props")
	public PropertiesFactoryBean propertiesFactoryBean(@Qualifier("prop")Properties properties) {
		PropertiesFactoryBean factoryBean = new PropertiesFactoryBean();
		//加载一个属性文件
		factoryBean.setProperties(properties);
		
		/*
		 * 用来加装多个属性文件,其中属性名称相同的,后加载的会覆盖之前加载的
		 */
//		Properties properties1 = new Properties();
//		Properties properties2 = new Properties();
//		try {
//			properties1.load(this.getClass().getClassLoader().getResourceAsStream("externals/app.properties"));
//			properties2.load(this.getClass().getClassLoader().getResourceAsStream("externals.properties"));
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
//		factoryBean.setPropertiesArray(properties1, properties2);
		return factoryBean;
	}
 
@Test
public void byTypeAutowireWithPrimaryInParentFactory() throws Exception {
	CountingFactory.reset();
	DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
	parent.getBeanDefinition("props1").setPrimary(true);
	parent.preInstantiateSingletons();
	DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
	RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class);
	robDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
	robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally"));
	child.registerBeanDefinition("rob2", robDef);
	RootBeanDefinition propsDef = new RootBeanDefinition(PropertiesFactoryBean.class);
	propsDef.getPropertyValues().add("properties", "name=props3");
	child.registerBeanDefinition("props3", propsDef);
	TestBean rob = (TestBean) child.getBean("rob2");
	assertEquals("props1", rob.getSomeProperties().getProperty("name"));
	assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
 
@Test
public void byTypeAutowireWithPrimaryOverridingParentFactory() throws Exception {
	CountingFactory.reset();
	DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
	parent.preInstantiateSingletons();
	DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
	RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class);
	robDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
	robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally"));
	child.registerBeanDefinition("rob2", robDef);
	RootBeanDefinition propsDef = new RootBeanDefinition(PropertiesFactoryBean.class);
	propsDef.getPropertyValues().add("properties", "name=props3");
	propsDef.setPrimary(true);
	child.registerBeanDefinition("props3", propsDef);
	TestBean rob = (TestBean) child.getBean("rob2");
	assertEquals("props3", rob.getSomeProperties().getProperty("name"));
	assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
 
@Test
public void byTypeAutowireWithPrimaryInParentAndChild() throws Exception {
	CountingFactory.reset();
	DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
	parent.getBeanDefinition("props1").setPrimary(true);
	parent.preInstantiateSingletons();
	DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
	RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class);
	robDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
	robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally"));
	child.registerBeanDefinition("rob2", robDef);
	RootBeanDefinition propsDef = new RootBeanDefinition(PropertiesFactoryBean.class);
	propsDef.getPropertyValues().add("properties", "name=props3");
	propsDef.setPrimary(true);
	child.registerBeanDefinition("props3", propsDef);
	TestBean rob = (TestBean) child.getBean("rob2");
	assertEquals("props3", rob.getSomeProperties().getProperty("name"));
	assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
 
@Test
public void testExpressionInStringArray() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	BeanExpressionResolver beanExpressionResolver = mock(BeanExpressionResolver.class);
	when(beanExpressionResolver.evaluate(eq("#{foo}"), ArgumentMatchers.any(BeanExpressionContext.class)))
			.thenReturn("classpath:/org/springframework/beans/factory/xml/util.properties");
	bf.setBeanExpressionResolver(beanExpressionResolver);

	RootBeanDefinition rbd = new RootBeanDefinition(PropertiesFactoryBean.class);
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("locations", new String[]{"#{foo}"});
	rbd.setPropertyValues(pvs);
	bf.registerBeanDefinition("myProperties", rbd);
	Properties properties = (Properties) bf.getBean("myProperties");
	assertEquals("bar", properties.getProperty("foo"));
}
 
源代码11 项目: Almost-Famous   文件: SchedulerConfig.java
@Bean
public SchedulerFactoryBean schedulerFactoryBean() throws IOException {
    //获取配置属性
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
    //在quartz.properties中的属性被读取并注入后再初始化对象
    propertiesFactoryBean.afterPropertiesSet();
    //创建SchedulerFactoryBean
    SchedulerFactoryBean factory = new SchedulerFactoryBean();
    factory.setQuartzProperties(propertiesFactoryBean.getObject());
    //使用数据源,自定义数据源
    factory.setJobFactory(jobFactory);
    factory.setWaitForJobsToCompleteOnShutdown(true);//这样当spring关闭时,会等待所有已经启动的quartz job结束后spring才能完全shutdown。
    factory.setOverwriteExistingJobs(false);
    factory.setStartupDelay(1);
    return factory;
}
 
源代码12 项目: Almost-Famous   文件: RobotScheduledConfig.java
@Bean
public SchedulerFactoryBean schedulerFactoryBean() throws IOException {
    //获取配置属性
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
    //在quartz.properties中的属性被读取并注入后再初始化对象
    propertiesFactoryBean.afterPropertiesSet();
    //创建SchedulerFactoryBean
    SchedulerFactoryBean factory = new SchedulerFactoryBean();
    factory.setQuartzProperties(propertiesFactoryBean.getObject());
    //使用数据源,自定义数据源
    factory.setJobFactory(jobFactory);
    factory.setWaitForJobsToCompleteOnShutdown(true);//这样当spring关闭时,会等待所有已经启动的quartz job结束后spring才能完全shutdown。
    factory.setOverwriteExistingJobs(false);
    factory.setStartupDelay(1);
    return factory;
}
 
@Test
public void byTypeAutowireWithPrimaryInParentFactory() throws Exception {
	CountingFactory.reset();
	DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
	parent.getBeanDefinition("props1").setPrimary(true);
	parent.preInstantiateSingletons();
	DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
	RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class);
	robDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
	robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally"));
	child.registerBeanDefinition("rob2", robDef);
	RootBeanDefinition propsDef = new RootBeanDefinition(PropertiesFactoryBean.class);
	propsDef.getPropertyValues().add("properties", "name=props3");
	child.registerBeanDefinition("props3", propsDef);
	TestBean rob = (TestBean) child.getBean("rob2");
	assertEquals("props1", rob.getSomeProperties().getProperty("name"));
	assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
 
@Test
public void byTypeAutowireWithPrimaryOverridingParentFactory() throws Exception {
	CountingFactory.reset();
	DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
	parent.preInstantiateSingletons();
	DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
	RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class);
	robDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
	robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally"));
	child.registerBeanDefinition("rob2", robDef);
	RootBeanDefinition propsDef = new RootBeanDefinition(PropertiesFactoryBean.class);
	propsDef.getPropertyValues().add("properties", "name=props3");
	propsDef.setPrimary(true);
	child.registerBeanDefinition("props3", propsDef);
	TestBean rob = (TestBean) child.getBean("rob2");
	assertEquals("props3", rob.getSomeProperties().getProperty("name"));
	assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
 
@Test
public void byTypeAutowireWithPrimaryInParentAndChild() throws Exception {
	CountingFactory.reset();
	DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
	parent.getBeanDefinition("props1").setPrimary(true);
	parent.preInstantiateSingletons();
	DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
	RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class);
	robDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
	robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally"));
	child.registerBeanDefinition("rob2", robDef);
	RootBeanDefinition propsDef = new RootBeanDefinition(PropertiesFactoryBean.class);
	propsDef.getPropertyValues().add("properties", "name=props3");
	propsDef.setPrimary(true);
	child.registerBeanDefinition("props3", propsDef);
	TestBean rob = (TestBean) child.getBean("rob2");
	assertEquals("props3", rob.getSomeProperties().getProperty("name"));
	assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
 
@Test
public void testExpressionInStringArray() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	BeanExpressionResolver beanExpressionResolver = mock(BeanExpressionResolver.class);
	when(beanExpressionResolver.evaluate(eq("#{foo}"), Matchers.any(BeanExpressionContext.class)))
			.thenReturn("classpath:/org/springframework/beans/factory/xml/util.properties");
	bf.setBeanExpressionResolver(beanExpressionResolver);

	RootBeanDefinition rbd = new RootBeanDefinition(PropertiesFactoryBean.class);
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("locations", new String[]{"#{foo}"});
	rbd.setPropertyValues(pvs);
	bf.registerBeanDefinition("myProperties", rbd);
	Properties properties = (Properties) bf.getBean("myProperties");
	assertEquals("bar", properties.getProperty("foo"));
}
 
源代码17 项目: micro-server   文件: PropertyFileConfig.java
@Bean
public Properties propertyFactory() throws IOException {
    List<Resource> resources = loadPropertyResource();
    PropertiesFactoryBean factory = new PropertiesFactoryBean();
    factory.setLocations(resources.toArray(new Resource[resources.size()]));
    factory.afterPropertiesSet();
    Properties props = factory.getObject();

    new ConfigAccessor().get()
                        .getProperties()
                        .stream()
                        .forEach(e -> {
                            if (props.getProperty(e._1()) == null) {
                                props.put(e._1(), e._2());
                            }
                        });

    System.getProperties()
          .entrySet()
          .forEach(e -> props.put(e.getKey(), e.getValue()));

    return props;
}
 
源代码18 项目: micro-server   文件: SSLConfig.java
@Bean
public static SSLProperties sslProperties() throws IOException {
	PropertiesFactoryBean factory = new PropertiesFactoryBean();
	URL url = SSLConfig.class.getClassLoader().getResource("ssl.properties");
	if (url != null) {
		Resource reource = new UrlResource(url);
		factory.setLocation(reource);
		factory.afterPropertiesSet();
		Properties properties = factory.getObject();
		return SSLProperties.builder()
				.keyStoreFile(properties.getProperty(keyStoreFile))
				.keyStorePass(properties.getProperty(keyStorePass))
				.trustStoreFile(properties.getProperty(trustStoreFile))
				.trustStorePass(properties.getProperty(trustStorePass))
				.keyStoreType(properties.getProperty(keyStoreType))
				.keyStoreProvider(properties.getProperty(keyStoreProvider))
				.trustStoreType(properties.getProperty(trustStoreType))
				.trustStoreProvider(properties.getProperty(trustStoreProvider))
				.clientAuth(properties.getProperty(clientAuth))
				.ciphers(properties.getProperty(ciphers))
				.protocol(properties.getProperty(protocol)).build();
	}
	return null;
}
 
源代码19 项目: logsniffer   文件: CoreAppConfig.java
@Bean(name = { BEAN_LOGSNIFFER_PROPS })
@Autowired
public PropertiesFactoryBean logSnifferProperties(final ApplicationContext ctx) throws IOException {
	if (ctx.getEnvironment().acceptsProfiles("!" + ContextProvider.PROFILE_NONE_QA)) {
		final File qaFile = File.createTempFile("logsniffer", "qa");
		qaFile.delete();
		final String qaHomeDir = qaFile.getPath();
		logger.info("QA mode active, setting random home directory: {}", qaHomeDir);
		System.setProperty("logsniffer.home", qaHomeDir);
	}
	final PathMatchingResourcePatternResolver pathMatcher = new PathMatchingResourcePatternResolver();
	Resource[] classPathProperties = pathMatcher.getResources("classpath*:/config/**/logsniffer-*.properties");
	final Resource[] metainfProperties = pathMatcher
			.getResources("classpath*:/META-INF/**/logsniffer-*.properties");
	final PropertiesFactoryBean p = new PropertiesFactoryBean();
	for (final Resource r : metainfProperties) {
		classPathProperties = (Resource[]) ArrayUtils.add(classPathProperties, r);
	}
	classPathProperties = (Resource[]) ArrayUtils.add(classPathProperties,
			new FileSystemResource(System.getProperty("logsniffer.home") + "/" + LOGSNIFFER_PROPERTIES_FILE));
	p.setLocations(classPathProperties);
	p.setProperties(System.getProperties());
	p.setLocalOverride(true);
	p.setIgnoreResourceNotFound(true);
	return p;
}
 
源代码20 项目: vividus   文件: ConfigurationResolver.java
private static Properties loadProperties(Resource... propertyResources) throws IOException
{
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setFileEncoding(StandardCharsets.UTF_8.name());
    propertiesFactoryBean.setLocations(propertyResources);
    propertiesFactoryBean.setSingleton(false);
    return propertiesFactoryBean.getObject();
}
 
@Test
public void testEvents() {
	ComponentDefinition propertiesComponent = this.listener.getComponentDefinition("myProperties");
	assertNotNull("Event for 'myProperties' not sent", propertiesComponent);
	AbstractBeanDefinition propertiesBean = (AbstractBeanDefinition) propertiesComponent.getBeanDefinitions()[0];
	assertEquals("Incorrect BeanDefinition", PropertiesFactoryBean.class, propertiesBean.getBeanClass());

	ComponentDefinition constantComponent = this.listener.getComponentDefinition("min");
	assertNotNull("Event for 'min' not sent", propertiesComponent);
	AbstractBeanDefinition constantBean = (AbstractBeanDefinition) constantComponent.getBeanDefinitions()[0];
	assertEquals("Incorrect BeanDefinition", FieldRetrievingFactoryBean.class, constantBean.getBeanClass());
}
 
@Test
public void testRegisterExistingSingletonWithNameOverriding() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	Properties p = new Properties();
	p.setProperty("test.(class)", TestBean.class.getName());
	p.setProperty("test.name", "Tony");
	p.setProperty("test.age", "48");
	p.setProperty("test.spouse(ref)", "singletonObject");
	(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
	lbf.registerBeanDefinition("singletonObject", new RootBeanDefinition(PropertiesFactoryBean.class));
	Object singletonObject = new TestBean();
	lbf.registerSingleton("singletonObject", singletonObject);
	lbf.preInstantiateSingletons();

	assertTrue(lbf.isSingleton("singletonObject"));
	assertEquals(TestBean.class, lbf.getType("singletonObject"));
	TestBean test = (TestBean) lbf.getBean("test");
	assertEquals(singletonObject, lbf.getBean("singletonObject"));
	assertEquals(singletonObject, test.getSpouse());

	Map<?, ?>  beansOfType = lbf.getBeansOfType(TestBean.class, false, true);
	assertEquals(2, beansOfType.size());
	assertTrue(beansOfType.containsValue(test));
	assertTrue(beansOfType.containsValue(singletonObject));

	beansOfType = lbf.getBeansOfType(null, false, true);

	Iterator<String> beanNames = lbf.getBeanNamesIterator();
	assertEquals("test", beanNames.next());
	assertEquals("singletonObject", beanNames.next());
	assertFalse(beanNames.hasNext());
	assertEquals(2, beansOfType.size());

	assertTrue(lbf.containsSingleton("test"));
	assertTrue(lbf.containsSingleton("singletonObject"));
	assertTrue(lbf.containsBeanDefinition("test"));
	assertTrue(lbf.containsBeanDefinition("singletonObject"));
}
 
源代码23 项目: spring-boot-demo   文件: SchedulerConfig.java
/**
 * 加载配置属性
 *
 * @return
 * @throws IOException
 */
@Bean
public Properties quartzProperties() throws IOException {
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(new ClassPathResource("/spring-quartz.properties"));
    propertiesFactoryBean.afterPropertiesSet();
    return propertiesFactoryBean.getObject();
}
 
@Test
public void testEvents() {
	ComponentDefinition propertiesComponent = this.listener.getComponentDefinition("myProperties");
	assertNotNull("Event for 'myProperties' not sent", propertiesComponent);
	AbstractBeanDefinition propertiesBean = (AbstractBeanDefinition) propertiesComponent.getBeanDefinitions()[0];
	assertEquals("Incorrect BeanDefinition", PropertiesFactoryBean.class, propertiesBean.getBeanClass());

	ComponentDefinition constantComponent = this.listener.getComponentDefinition("min");
	assertNotNull("Event for 'min' not sent", propertiesComponent);
	AbstractBeanDefinition constantBean = (AbstractBeanDefinition) constantComponent.getBeanDefinitions()[0];
	assertEquals("Incorrect BeanDefinition", FieldRetrievingFactoryBean.class, constantBean.getBeanClass());
}
 
@Test
public void testRegisterExistingSingletonWithNameOverriding() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	Properties p = new Properties();
	p.setProperty("test.(class)", TestBean.class.getName());
	p.setProperty("test.name", "Tony");
	p.setProperty("test.age", "48");
	p.setProperty("test.spouse(ref)", "singletonObject");
	(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
	lbf.registerBeanDefinition("singletonObject", new RootBeanDefinition(PropertiesFactoryBean.class));
	Object singletonObject = new TestBean();
	lbf.registerSingleton("singletonObject", singletonObject);
	lbf.preInstantiateSingletons();

	assertTrue(lbf.isSingleton("singletonObject"));
	assertEquals(TestBean.class, lbf.getType("singletonObject"));
	TestBean test = (TestBean) lbf.getBean("test");
	assertEquals(singletonObject, lbf.getBean("singletonObject"));
	assertEquals(singletonObject, test.getSpouse());

	Map<?, ?>  beansOfType = lbf.getBeansOfType(TestBean.class, false, true);
	assertEquals(2, beansOfType.size());
	assertTrue(beansOfType.containsValue(test));
	assertTrue(beansOfType.containsValue(singletonObject));

	beansOfType = lbf.getBeansOfType(null, false, true);

	Iterator<String> beanNames = lbf.getBeanNamesIterator();
	assertEquals("test", beanNames.next());
	assertEquals("singletonObject", beanNames.next());
	assertFalse(beanNames.hasNext());
	assertEquals(2, beansOfType.size());

	assertTrue(lbf.containsSingleton("test"));
	assertTrue(lbf.containsSingleton("singletonObject"));
	assertTrue(lbf.containsBeanDefinition("test"));
	assertTrue(lbf.containsBeanDefinition("singletonObject"));
}
 
源代码26 项目: fabric-net-server   文件: MybatisTableConfig.java
@Bean
public PropertiesFactoryBean configProperties() throws Exception{
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    propertiesFactoryBean.setLocations(resolver.getResources("classpath*:application.properties"));
    return propertiesFactoryBean;
}
 
源代码27 项目: pacbot   文件: PacmanQuartzConfiguration.java
@Bean
public Properties quartzProperties() throws IOException {
	PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
	propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
	propertiesFactoryBean.afterPropertiesSet();
	return propertiesFactoryBean.getObject();
}
 
源代码28 项目: zkdoctor   文件: SchedulerConfig.java
/**
 * 初始化quartz配置
 *
 * @return
 * @throws IOException
 */
@Bean
public Properties quartzProperties() throws IOException {
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
    propertiesFactoryBean.afterPropertiesSet();
    return propertiesFactoryBean.getObject();
}
 
源代码29 项目: TAC   文件: SchedulerConfig.java
@Bean
public Properties quartzProperties() throws IOException {
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
    //在quartz.properties中的属性被读取并注入后再初始化对象
    propertiesFactoryBean.afterPropertiesSet();
    return propertiesFactoryBean.getObject();
}
 
源代码30 项目: yyblog   文件: QuartzConfigration.java
@Bean
public Properties quartzProperties() throws IOException {
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(new ClassPathResource("/config/quartz.properties"));
    propertiesFactoryBean.afterPropertiesSet();
    return propertiesFactoryBean.getObject();
}
 
源代码评论
动弹
沙发等你来抢
 类方法
 同包方法