Java Code Examples for org.springframework.beans.factory.config.PropertiesFactoryBean#getObject()

The following examples show how to use org.springframework.beans.factory.config.PropertiesFactoryBean#getObject() . 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: 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 2
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 3
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 4
Source File: SchedulerConfig.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 加载配置属性
 *
 * @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();
}
 
Example 5
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 6
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 7
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 8
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 9
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 10
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 11
Source File: QuartzSchedulerConfig.java    From spring-boot-quartz-demo with MIT License 5 votes vote down vote up
/**
 * Configure quartz using properties file
 */
@Bean
public Properties quartzProperties() throws IOException {
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
    propertiesFactoryBean.afterPropertiesSet();
    return propertiesFactoryBean.getObject();
}
 
Example 12
Source File: ChildApplicationContextFactory.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Instantiates a new application context state.
 * 
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
protected ApplicationContextState(boolean allowInitAccess ) throws IOException
{
    this.allowInitAccess = allowInitAccess;
    // Load the property defaults
    PropertiesFactoryBean factory = new PropertiesFactoryBean();
    factory.setPropertiesPersister(getPersister());
    factory.setLocations(getParent().getResources(
            ChildApplicationContextFactory.CLASSPATH_PREFIX + getCategory() + '/' + getTypeName()
                    + ChildApplicationContextFactory.PROPERTIES_SUFFIX));
    factory.afterPropertiesSet();
    this.properties = (Properties) factory.getObject();
}
 
Example 13
Source File: PropertiesUtil.java    From griffin with Apache License 2.0 5 votes vote down vote up
public static Properties getProperties(String path, Resource resource) {
    PropertiesFactoryBean propFactoryBean = new PropertiesFactoryBean();
    Properties properties = null;
    try {
        propFactoryBean.setLocation(resource);
        propFactoryBean.afterPropertiesSet();
        properties = propFactoryBean.getObject();
        LOGGER.info("Read properties successfully from {}.", path);
    } catch (IOException e) {
        LOGGER.error("Get properties from {} failed. {}", path, e);
    }
    return properties;
}
 
Example 14
Source File: QuartzConfigration.java    From yyblog with MIT License 5 votes vote down vote up
@Bean
public Properties quartzProperties() throws IOException {
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(new ClassPathResource("/config/quartz.properties"));
    propertiesFactoryBean.afterPropertiesSet();
    return propertiesFactoryBean.getObject();
}
 
Example 15
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 16
Source File: SchedulerConfig.java    From zkdoctor with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化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();
}
 
Example 17
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();
}
 
Example 18
Source File: ConfigurationResolver.java    From vividus with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 19
Source File: QrtzScheduler.java    From tutorials with MIT License 4 votes vote down vote up
public Properties quartzProperties() throws IOException {
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
    propertiesFactoryBean.afterPropertiesSet();
    return propertiesFactoryBean.getObject();
}