org.springframework.beans.factory.config.PropertiesFactoryBean Java Examples

The following examples show how to use org.springframework.beans.factory.config.PropertiesFactoryBean. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SchedulerConfig.java    From Almost-Famous with MIT License 7 votes vote down vote up
@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;
}
 
Example #2
Source File: AutowireWithExclusionTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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());
}
 
Example #3
Source File: CoreAppConfig.java    From logsniffer with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example #4
Source File: AutowireWithExclusionTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #5
Source File: AutowireWithExclusionTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #6
Source File: AutowireWithExclusionTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #7
Source File: RobotScheduledConfig.java    From Almost-Famous with MIT License 6 votes vote down vote up
@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;
}
 
Example #8
Source File: DefaultListableBeanFactoryTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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"));
}
 
Example #9
Source File: AutowireWithExclusionTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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());
}
 
Example #10
Source File: AutowireWithExclusionTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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());
}
 
Example #11
Source File: DefaultListableBeanFactoryTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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"));
}
 
Example #12
Source File: SpELConfig.java    From Project with Apache License 2.0 6 votes vote down vote up
/**
	* <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;
	}
 
Example #13
Source File: SSLConfig.java    From micro-server with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #14
Source File: AutowireWithExclusionTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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());
}
 
Example #15
Source File: AutowireWithExclusionTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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());
}
 
Example #16
Source File: AutowireWithExclusionTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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());
}
 
Example #17
Source File: PropertyFileConfig.java    From micro-server with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #18
Source File: DefaultListableBeanFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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"));
}
 
Example #19
Source File: QuartzConfiguration.java    From seppb with MIT License 6 votes vote down vote up
@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;
}
 
Example #20
Source File: DefaultListableBeanFactoryTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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"));
}
 
Example #21
Source File: SchedulerConfig.java    From quartz-manager with Apache License 2.0 5 votes vote down vote up
@Bean
public Properties quartzProperties() throws IOException {
	PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
	propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
	propertiesFactoryBean.afterPropertiesSet();
	return propertiesFactoryBean.getObject();
}
 
Example #22
Source File: SchedulerConfig.java    From TAC with MIT License 5 votes vote down vote up
@Bean
public Properties quartzProperties() throws IOException {
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
    //在quartz.properties中的属性被读取并注入后再初始化对象
    propertiesFactoryBean.afterPropertiesSet();
    return propertiesFactoryBean.getObject();
}
 
Example #23
Source File: QuartzConfig.java    From lemonaid with MIT License 5 votes vote down vote up
@Bean
public Properties quartzProperties() {
	PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
	propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
	Properties properties = null;
	try {
		propertiesFactoryBean.afterPropertiesSet();
		properties = propertiesFactoryBean.getObject();

	} catch (IOException e) {
		log.warn("Cannot load quartz.properties.");
	}

	return properties;
}
 
Example #24
Source File: UtilNamespaceHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #25
Source File: SpringUtils.java    From onetwo with Apache License 2.0 5 votes vote down vote up
public static PropertiesFactoryBean createPropertiesBySptring(JFishProperties properties, String...classpaths) {
//		PropertiesFactoryBean pfb = new PropertiesFactoryBean();
		PropertiesFactoryBean pfb = new JFishPropertiesFactoryBean(properties);
		pfb.setIgnoreResourceNotFound(true);
		org.springframework.core.io.Resource[] resources = new org.springframework.core.io.Resource[classpaths.length];
		int index = 0;
		for(String classpath : classpaths){
			resources[index++] = classpath(classpath);
		}
		pfb.setLocations(resources);
		return pfb;
	}
 
Example #26
Source File: SchedulerConfig.java    From springboot-quartz with MIT License 5 votes vote down vote up
@Bean
public Properties quartzProperties() throws IOException {
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
    propertiesFactoryBean.afterPropertiesSet();
    return propertiesFactoryBean.getObject();
}
 
Example #27
Source File: TestContextConfiguration3.java    From spring-boot-starter-quartz with Apache License 2.0 5 votes vote down vote up
@Bean(name = QuartzSchedulerAutoConfiguration.QUARTZ_PROPERTIES_BEAN_NAME)
public Properties quartzProperties(
		@Autowired ApplicationContext applicationContext,
		@Autowired QuartzSchedulerProperties properties) throws IOException {
	
	System.out.println("my overridden quartz.properties loading");
	
	PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
	propertiesFactoryBean.setLocation(applicationContext.getResource("classpath:overriddenQuartzScheduler.properties"));
	propertiesFactoryBean.afterPropertiesSet();
	return propertiesFactoryBean.getObject();
}
 
Example #28
Source File: QuartzSchedulerAutoConfiguration.java    From spring-boot-starter-quartz with Apache License 2.0 5 votes vote down vote up
private static Properties loadConfigLocationProperties(ApplicationContext applicationContext, 
		QuartzSchedulerProperties properties) throws IOException {
	
	String location = properties.getPropertiesConfigLocation();
	if(null == location || location.trim().length() == 0) {
		location = QuartzSchedulerProperties.DEFAULT_CONFIG_LOCATION;
		LOGGER.debug("using default 'quartz.properties' from classpath: " + location);
	} else {
		LOGGER.debug("using 'quartz.properties' from location: " + location);
	}
	PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
	propertiesFactoryBean.setLocation(applicationContext.getResource(location));
	propertiesFactoryBean.afterPropertiesSet();
	return propertiesFactoryBean.getObject();
}
 
Example #29
Source File: SpringUtils.java    From onetwo with Apache License 2.0 5 votes vote down vote up
public static JFishProperties loadAsJFishProperties(String... classpaths){
	PropertiesFactoryBean pfb = createPropertiesBySptring(classpaths);
   	try {
		pfb.afterPropertiesSet();
		JFishProperties properties = (JFishProperties)pfb.getObject();
		return properties;
	} catch (IOException e) {
		throw new BaseException("load config error: " + e.getMessage(), e);
	}
}
 
Example #30
Source File: PacmanQuartzConfiguration.java    From pacbot with Apache License 2.0 5 votes vote down vote up
@Bean
public Properties quartzProperties() throws IOException {
	PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
	propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
	propertiesFactoryBean.afterPropertiesSet();
	return propertiesFactoryBean.getObject();
}