當前位置: 首頁>>代碼示例>>Java>>正文


Java PropertiesFactoryBean類代碼示例

本文整理匯總了Java中org.springframework.beans.factory.config.PropertiesFactoryBean的典型用法代碼示例。如果您正苦於以下問題:Java PropertiesFactoryBean類的具體用法?Java PropertiesFactoryBean怎麽用?Java PropertiesFactoryBean使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PropertiesFactoryBean類屬於org.springframework.beans.factory.config包,在下文中一共展示了PropertiesFactoryBean類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getConfig

import org.springframework.beans.factory.config.PropertiesFactoryBean; //導入依賴的package包/類
public Properties getConfig(ConfigurableEnvironment env) throws IOException {
    PropertiesFactoryBean config = new PropertiesFactoryBean();
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    List<Resource> resouceList = InstanceUtil.newArrayList();
    try {
        Resource[] resources = resolver.getResources("classpath*:config/*.properties");
        for (Resource resource : resources) {
            resouceList.add(resource);
        }
    } catch (Exception e) {
        logger.error("", e);
    }
    config.setLocations(resouceList.toArray(new Resource[]{}));
    config.afterPropertiesSet();
    return config.getObject();
}
 
開發者ID:iBase4J,項目名稱:iBase4J-Common,代碼行數:17,代碼來源:Configs.java

示例2: quartzProperties

import org.springframework.beans.factory.config.PropertiesFactoryBean; //導入依賴的package包/類
@Bean
public Properties quartzProperties() throws IOException {
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
    propertiesFactoryBean.afterPropertiesSet();
    return propertiesFactoryBean.getObject();
}
 
開發者ID:farchanjo,項目名稱:webcron,代碼行數:8,代碼來源:QuartzConfig.java

示例3: findNamedQueries

import org.springframework.beans.factory.config.PropertiesFactoryBean; //導入依賴的package包/類
static NamedQueries findNamedQueries(Class<?> repositoryClass) {
    try {
        RepositoryConfigurationExtension config = new SnowdropRepositoryConfigExtension();
        String location = config.getDefaultNamedQueryLocation();

        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(repositoryClass.getClassLoader());
        ResourceArrayPropertyEditor editor = new ResourceArrayPropertyEditor(resolver, null);
        editor.setAsText(location);
        Resource[] resources = (Resource[]) editor.getValue();

        PropertiesFactoryBean pfb = new PropertiesFactoryBean();
        pfb.setSingleton(false);
        pfb.setLocations(resources);
        pfb.setFileEncoding("UTF-8");
        Properties properties = pfb.getObject();

        return new PropertiesBasedNamedQueries(properties);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
 
開發者ID:snowdrop,項目名稱:spring-data-snowdrop,代碼行數:22,代碼來源:CdiUtils.java

示例4: byTypeAutowireWithPrimaryInParentFactory

import org.springframework.beans.factory.config.PropertiesFactoryBean; //導入依賴的package包/類
@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());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:AutowireWithExclusionTests.java

示例5: byTypeAutowireWithPrimaryOverridingParentFactory

import org.springframework.beans.factory.config.PropertiesFactoryBean; //導入依賴的package包/類
@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());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:AutowireWithExclusionTests.java

示例6: byTypeAutowireWithPrimaryInParentAndChild

import org.springframework.beans.factory.config.PropertiesFactoryBean; //導入依賴的package包/類
@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());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:AutowireWithExclusionTests.java

示例7: testExpressionInStringArray

import org.springframework.beans.factory.config.PropertiesFactoryBean; //導入依賴的package包/類
@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"));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:17,代碼來源:DefaultListableBeanFactoryTests.java

示例8: build

import org.springframework.beans.factory.config.PropertiesFactoryBean; //導入依賴的package包/類
public SchedulerFactoryBean build() throws Exception {
	SchedulerFactoryBean bean = new SchedulerFactoryBean();
	PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
	propertiesFactoryBean.setLocation(new ClassPathResource(config));
	propertiesFactoryBean.afterPropertiesSet();
	Properties props = propertiesFactoryBean.getObject();
	List<Trigger> triggers = Lists.newArrayList();
	List<JobModel> jobList = getJobs(props);
	for (JobModel job : jobList) {
		if (!job.isEnable()) {
			continue;
		}
		JobDetailFactoryBean detail = createJobDetail(job.getName(), Class.forName(job.getJob()));
		CronTriggerFactoryBean trigger = createCronTrigger(job.getName(), detail.getObject(), job.getCorn());
		CronTrigger t = trigger.getObject();
		triggers.add(t);
	}
	bean.setTriggers(triggers.toArray(new Trigger[0]));
	//bean.afterPropertiesSet();
	return bean;

}
 
開發者ID:mazhaoyong,項目名稱:api-server-seed,代碼行數:23,代碼來源:QuartzFactory.java

示例9: loadBackupProperty

import org.springframework.beans.factory.config.PropertiesFactoryBean; //導入依賴的package包/類
private Properties loadBackupProperty(String filePath) {
    PropertiesFactoryBean propertiesFactory = new PropertiesFactoryBean();
    Properties props = new Properties();
    try {
        FileSystemResource fileSystemResource = new FileSystemResource(filePath);
        propertiesFactory.setLocation(fileSystemResource);

        propertiesFactory.afterPropertiesSet();
        props = propertiesFactory.getObject();

    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }

    return props;
}
 
開發者ID:darren-fu,項目名稱:spring-cloud-config-support,代碼行數:18,代碼來源:CloudConfigSupportConfiguration.java

示例10: testWithPropertiesFile

import org.springframework.beans.factory.config.PropertiesFactoryBean; //導入依賴的package包/類
@Test
public void testWithPropertiesFile() throws Exception {
    PropertiesFactoryBean pfb = new PropertiesFactoryBean();
    FileSystemResource pathResource = new FileSystemResource("test.properties");
    File file = pathResource.getFile();
    if (!file.exists()) {
        file.createNewFile();
    }
    System.out.println("pathResource:" + pathResource.getPath());
    System.out.println("pathResource:" + pathResource.getFile());
    pfb.setLocation(pathResource);
    pfb.afterPropertiesSet();
    Properties props = (Properties) pfb.getObject();
    System.out.println(props.get("a"));
    props.setProperty("a", "DDD");
    System.out.println(props.get("a"));
    FileOutputStream oFile = new FileOutputStream(pathResource.getFile());
    props.store(oFile, "Comment");
    oFile.close();
    file.deleteOnExit();
}
 
開發者ID:darren-fu,項目名稱:spring-cloud-config-support,代碼行數:22,代碼來源:TestProperty.java

示例11: populateSubsystemBeanFactory

import org.springframework.beans.factory.config.PropertiesFactoryBean; //導入依賴的package包/類
protected void populateSubsystemBeanFactory(final ConfigurableListableBeanFactory beanFactory)
{
    try
    {
        // build effective properties
        final PropertiesFactoryBean factory = new PropertiesFactoryBean();
        factory.setPropertiesArray(new Properties[] { this.fixedConfigProperties, this.runtimeProperties });
        factory.afterPropertiesSet();
        final Properties subsystemProperties = factory.getObject();
        beanFactory.registerSingleton(BEAN_NAME_SUBSYSTEM_PROPERTIES, subsystemProperties);
    }
    catch (final IOException e)
    {
        throw new AlfrescoRuntimeException("Error instantiating effective subsystem properties", e);
    }
}
 
開發者ID:Acosix,項目名稱:alfresco-utility,代碼行數:17,代碼來源:SubsystemWithClassLoaderState.java

示例12: propertyFactory

import org.springframework.beans.factory.config.PropertiesFactoryBean; //導入依賴的package包/類
@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;
}
 
開發者ID:aol,項目名稱:micro-server,代碼行數:24,代碼來源:PropertyFileConfig.java

示例13: sslProperties

import org.springframework.beans.factory.config.PropertiesFactoryBean; //導入依賴的package包/類
@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;
}
 
開發者ID:aol,項目名稱:micro-server,代碼行數:25,代碼來源:SSLConfig.java

示例14: logSnifferProperties

import org.springframework.beans.factory.config.PropertiesFactoryBean; //導入依賴的package包/類
@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;
}
 
開發者ID:logsniffer,項目名稱:logsniffer,代碼行數:27,代碼來源:CoreAppConfig.java

示例15: propertyUserDetailsService

import org.springframework.beans.factory.config.PropertiesFactoryBean; //導入依賴的package包/類
@Bean
public InMemoryUserDetailsManager propertyUserDetailsService() throws IOException {

    String env = System.getenv(ENVIRONMENT);

    if (env == null) {
        env = System.getProperty(ENVIRONMENT, "dev");
    }

    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocations(new ClassPathResource("usercredentials-" + env + ".properties"));
    propertiesFactoryBean.afterPropertiesSet();

    Properties users = propertiesFactoryBean.getObject();

    return new InMemoryUserDetailsManager(users);
}
 
開發者ID:Contargo,項目名稱:iris,代碼行數:18,代碼來源:SecurityConfig.java


注:本文中的org.springframework.beans.factory.config.PropertiesFactoryBean類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。