QuartzConfigProperties.java 1.17 KB
package com.yoho.quartz.scheduler;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import java.util.Properties;

/**
 * Author:yanzhang.fu
 * Date:2018/1/29
 * Description:
 * Modified By:
 **/
public class QuartzConfigProperties implements FactoryBean {

    private Resource customConfigLocation;

    @Override
    public Object getObject() throws Exception {
        if (customConfigLocation == null) {
            return null;
        }
        Properties prop = new Properties();
        try {
            PropertiesLoaderUtils.fillProperties(prop, this.customConfigLocation);
        } catch (Exception e) {
            return null;
        }
        return prop;
    }

    @Override
    public Class<?> getObjectType() {
        return Properties.class;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }

    public Resource getCustomConfigLocation() {
        return customConfigLocation;
    }

    public void setCustomConfigLocation(Resource customConfigLocation) {
        this.customConfigLocation = customConfigLocation;
    }
}