Example usage for org.springframework.beans.factory.config PropertyPlaceholderConfigurer setLocation

List of usage examples for org.springframework.beans.factory.config PropertyPlaceholderConfigurer setLocation

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config PropertyPlaceholderConfigurer setLocation.

Prototype

public void setLocation(Resource location) 

Source Link

Document

Set a location of a properties file to be loaded.

Usage

From source file:edu.chalmers.dat076.moviefinder.config.ApplicationConfig.java

@Bean
public static PropertyPlaceholderConfigurer getPropertyPlaceholderConfigurer() {
    PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
    ppc.setLocation(new ClassPathResource("application.properties"));
    ppc.setIgnoreUnresolvablePlaceholders(true);
    return ppc;/*from   ww  w .  j av  a  2s  . c  o m*/
}

From source file:es.galvarez.rest.config.SpringConfiguration.java

@Bean
public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
    PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
    ppc.setLocation(new ClassPathResource(DATASOURCE_FILE));
    return ppc;//w  w w .j  av  a  2s  .  c  om
}

From source file:org.cagrid.identifiers.namingauthority.util.SecurityUtil.java

public static void addAdmin(String naConfigurationFile, String naProperties, String adminUser)

        throws InvalidIdentifierException, URISyntaxException, NamingAuthorityConfigurationException,
        NamingAuthoritySecurityException, InvalidIdentifierValuesException {

    FileSystemResource naConfResource = new FileSystemResource(naConfigurationFile);
    FileSystemResource naPropertiesResource = new FileSystemResource(naProperties);

    XmlBeanFactory factory = new XmlBeanFactory(naConfResource);
    PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
    cfg.setLocation(naPropertiesResource);
    cfg.postProcessBeanFactory(factory);

    NamingAuthorityImpl na = (NamingAuthorityImpl) factory.getBean("NamingAuthority",
            MaintainerNamingAuthority.class);
    na.getIdentifierDao().createInitialAdministrator(adminUser);

    //        KeyData kd = na.getKeyData(null, na.getSystemIdentifier(), Keys.ADMIN_USERS);
    //        if (kd == null) {
    //           System.err.println("KD IS NULL");
    //           kd = new KeyData();
    //        }//from   w w w  . ja  v a 2s . co m
    //        
    //        List<String> values = kd.getValues();
    //        if (values == null) {
    //           System.err.println("VALUES IS NULL");
    //           values = new ArrayList<String>();
    //        }
    //        
    //        if (values.contains(adminUser)) {
    //           throw new NamingAuthorityConfigurationException("Provided identity [" + adminUser + "] is already an administrator");
    //        }
    //        
    //        values.add(adminUser);
    //        
    //        IdentifierValues ivalues = new IdentifierValues();
    //        ivalues.put(Keys.ADMIN_USERS, kd);
    //        na.replaceKeys(null, na.getSystemIdentifier(), ivalues);
}

From source file:co.paralleluniverse.common.spring.SpringContainerHelper.java

public static ConfigurableApplicationContext createContext(String defaultDomain, Resource xmlResource,
        Object properties, BeanFactoryPostProcessor beanFactoryPostProcessor) {
    LOG.info("JAVA: {} {}, {}", new Object[] { System.getProperty("java.runtime.name"),
            System.getProperty("java.runtime.version"), System.getProperty("java.vendor") });
    LOG.info("OS: {} {}, {}", new Object[] { System.getProperty("os.name"), System.getProperty("os.version"),
            System.getProperty("os.arch") });
    LOG.info("DIR: {}", System.getProperty("user.dir"));

    final DefaultListableBeanFactory beanFactory = createBeanFactory();
    final GenericApplicationContext context = new GenericApplicationContext(beanFactory);
    context.registerShutdownHook();//from   ww w. ja va 2  s. com

    final PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer();
    propertyPlaceholderConfigurer
            .setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE);

    if (properties != null) {
        if (properties instanceof Resource)
            propertyPlaceholderConfigurer.setLocation((Resource) properties);
        else if (properties instanceof Properties)
            propertyPlaceholderConfigurer.setProperties((Properties) properties);
        else
            throw new IllegalArgumentException(
                    "Properties argument - " + properties + " - is of an unhandled type");
    }
    context.addBeanFactoryPostProcessor(propertyPlaceholderConfigurer);

    // MBean exporter
    //final MBeanExporter mbeanExporter = new AnnotationMBeanExporter();
    //mbeanExporter.setServer(ManagementFactory.getPlatformMBeanServer());
    //beanFactory.registerSingleton("mbeanExporter", mbeanExporter);
    context.registerBeanDefinition("mbeanExporter", getMBeanExporterBeanDefinition(defaultDomain));

    // inject bean names into components
    context.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {
        @Override
        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
            for (String beanName : beanFactory.getBeanDefinitionNames()) {
                try {
                    final BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
                    if (beanDefinition.getBeanClassName() != null) { // van be null for factory methods
                        final Class<?> beanClass = Class.forName(beanDefinition.getBeanClassName());
                        if (Component.class.isAssignableFrom(beanClass))
                            beanDefinition.getConstructorArgumentValues().addIndexedArgumentValue(0, beanName);
                    }
                } catch (Exception ex) {
                    LOG.error("Error loading bean " + beanName + " definition.", ex);
                    throw new Error(ex);
                }
            }
        }
    });

    if (beanFactoryPostProcessor != null)
        context.addBeanFactoryPostProcessor(beanFactoryPostProcessor);

    beanFactory.registerCustomEditor(org.w3c.dom.Element.class,
            co.paralleluniverse.common.util.DOMElementProprtyEditor.class);

    final Map<String, Object> beans = new HashMap<String, Object>();

    beanFactory.addBeanPostProcessor(new BeanPostProcessor() {
        @Override
        public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
            LOG.info("Loading bean {} [{}]", beanName, bean.getClass().getName());
            beans.put(beanName, bean);

            if (bean instanceof Service) {
                final BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
                Collection<String> dependencies = getBeanDependencies(beanDefinition);

                for (String dependeeName : dependencies) {
                    Object dependee = beanFactory.getBean(dependeeName);
                    if (dependee instanceof Service) {
                        ((Service) dependee).addDependedBy((Service) bean);
                        ((Service) bean).addDependsOn((Service) dependee);
                    }
                }
            }
            return bean;
        }

        @Override
        public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
            LOG.info("Bean {} [{}] loaded", beanName, bean.getClass().getName());
            return bean;
        }
    });

    final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) beanFactory);
    xmlReader.loadBeanDefinitions(xmlResource);

    // start container
    context.refresh();

    // Call .postInit() on all Components
    // There's probably a better way to do this
    try {
        for (Map.Entry<String, Object> entry : beans.entrySet()) {
            final String beanName = entry.getKey();
            final Object bean = entry.getValue();
            if (bean instanceof Component) {
                LOG.info("Performing post-initialization on bean {} [{}]", beanName, bean.getClass().getName());
                ((Component) bean).postInit();
            }
        }
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }

    return context;
}

From source file:com.aspose.showcase.qrcodegen.web.config.AppConfigProperties.java

@Bean
public PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
    PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer();
    propertyPlaceholderConfigurer.setLocation(new ClassPathResource("config.properties"));
    // Allow for other PropertyPlaceholderConfigurer instances.
    propertyPlaceholderConfigurer.setIgnoreUnresolvablePlaceholders(true);
    return propertyPlaceholderConfigurer;
}

From source file:org.ow2.proactive.scheduling.api.graphql.service.AuthenticationServiceTestConfig.java

@Bean
public PropertyPlaceholderConfigurer properties() throws Exception {
    PropertyPlaceholderConfigurer placeholderConfigurer = new PropertyPlaceholderConfigurer();
    placeholderConfigurer.setLocation(new ClassPathResource("application-test.properties"));
    return placeholderConfigurer;
}

From source file:me.philnate.textmanager.config.cfgMongo.java

@Bean
public PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
    PropertyPlaceholderConfigurer config = new PropertyPlaceholderConfigurer();
    config.setLocation(new ClassPathResource("git.properties"));
    return config;
}

From source file:org.araneaframework.ioc.spring.SimpleAraneaSpringDispatcherServlet.java

public void init() throws ServletException {
    beanFactory = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());

    rootConf = new XmlBeanFactory(
            new ClassPathResource("spring-property-conf/property-custom-webapp-aranea-conf.xml"), beanFactory);
    PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
    cfg.setLocation(new ClassPathResource("spring-property-conf/default-aranea-conf.properties"));

    Properties localConf = new Properties();
    try {//from   w w w .  jav a 2  s  .c o m
        if (getServletContext().getResource("/WEB-INF/aranea-conf.properties") != null)
            localConf.load(getServletContext().getResourceAsStream("/WEB-INF/aranea-conf.properties"));
    } catch (IOException e) {
        throw new ServletException(e);
    }
    cfg.setProperties(localConf);
    cfg.setLocalOverride(true);

    cfg.postProcessBeanFactory(rootConf);

    super.init();
}

From source file:org.alfresco.cacheserver.dropwizard.Application.java

/**
 * Creates a Spring property place holder configurer for use in a Spring context
 * from the given file path.// w w w.j av  a  2 s  .  c  om
 * 
 * @param springPropsFileName
 * @return the Spring property place holder configurer
 * @throws IOException 
 */
protected PropertyPlaceholderConfigurer loadSpringConfigurer(String yamlConfigFileLocation) throws IOException {
    if (StringUtils.isEmpty(yamlConfigFileLocation)) {
        throw new IllegalArgumentException("Config file location must not be empty");
    }
    logger.debug("Loading properties from '" + yamlConfigFileLocation + "'");
    PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
    configurer.setLocation(new FileSystemResource(yamlConfigFileLocation));
    configurer.setPropertiesPersister(new YamlPropertiesPersister());
    return configurer;
}

From source file:com.mmnaseri.dragonfly.sample.Config.java

@Bean
public PropertyPlaceholderConfigurer placeholderConfigurer() {
    final PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
    configurer.setLocation(new ClassPathResource("db.properties"));
    return configurer;
}