本文整理匯總了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();
}
示例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();
}
示例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);
}
}
示例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());
}
示例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());
}
示例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());
}
示例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"));
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}