Example usage for org.springframework.core.env Environment getProperty

List of usage examples for org.springframework.core.env Environment getProperty

Introduction

In this page you can find the example usage for org.springframework.core.env Environment getProperty.

Prototype

@Nullable
String getProperty(String key);

Source Link

Document

Return the property value associated with the given key, or null if the key cannot be resolved.

Usage

From source file:io.smalldata.ohmageomh.dsu.configuration.SocialConfig.java

/**
 * Register google social service connection. More connections (Facebook, Twitter, etc)
 * can be added here too./*w  ww .j  ava 2s. c o m*/
 *
 * @param config
 * @param environment
 */
@Override
public void addConnectionFactories(ConnectionFactoryConfigurer config, Environment environment) {

    OAuth2ConnectionFactory<Google> google = new OAuth2ConnectionFactory<Google>("google",
            new CustomGoogleOAuth2ServiceProvider(environment.getProperty("google.clientId"),
                    environment.getProperty("google.clientSecret")),
            new GoogleAdapter());
    config.addConnectionFactory(google);
}

From source file:com.indeed.iupload.web.controller.AppController.java

@Autowired
public AppController(Environment env) {
    try {//from  ww w.  j  a  va2s.com
        KerberosUtils.loginFromKeytab(env.getProperty("kerberos.principal"),
                env.getProperty("kerberos.keytab"));
    } catch (IOException e) {
        log.warn("Kerberos loging from keytab failed");
    }
}

From source file:com.solace.spring.boot.autoconfigure.SolaceJavaAutoCloudConfigurationTest.java

@Test(expected = NoSuchBeanDefinitionException.class)
public void noBeanIsCloudNoService() throws NoSuchBeanDefinitionException {
    load(CF_CLOUD_APP_ENV);//from  w  w w  .  j a va2 s.c om

    Environment env = context.getEnvironment();
    String VCAP_APPLICATION = env.getProperty("VCAP_APPLICATION");
    assertNotNull(VCAP_APPLICATION);
    assertEquals("{}", VCAP_APPLICATION);

    String VCAP_SERVICES = env.getProperty("VCAP_SERVICES");
    assertNull(VCAP_SERVICES);

    try {
        this.context.getBean(beanClass);
    } catch (NoSuchBeanDefinitionException e) {
        assertTrue(e.getBeanType().isAssignableFrom(beanClass));
        throw e;
    }
}

From source file:com.solace.spring.boot.autoconfigure.SolaceJavaAutoCloudConfigurationTest.java

@Test(expected = NoSuchBeanDefinitionException.class)
public void noBeanIsCloudWrongService() throws NoSuchBeanDefinitionException {
    load(CF_CLOUD_APP_ENV, CF_VCAP_SERVICES_OTHER);

    Environment env = context.getEnvironment();
    String VCAP_APPLICATION = env.getProperty("VCAP_APPLICATION");
    assertNotNull(VCAP_APPLICATION);/*from w w  w.  ja va2 s. co  m*/
    assertEquals("{}", VCAP_APPLICATION);

    String VCAP_SERVICES = env.getProperty("VCAP_SERVICES");
    assertNotNull(VCAP_SERVICES);
    assertFalse(VCAP_SERVICES.contains("solace-messaging"));

    try {
        this.context.getBean(beanClass);
    } catch (NoSuchBeanDefinitionException e) {
        assertTrue(e.getBeanType().isAssignableFrom(beanClass));
        throw e;
    }
}

From source file:com.solace.spring.boot.autoconfigure.SolaceJavaAutoCloudConfigurationTest.java

@Test
public void hasBeanIsCloudHasService() {
    makeCloudEnv();/*w ww.  j  av  a2 s .  c om*/

    String JSONString = addOneSolaceService("VCAP_SERVICES");
    String CF_VCAP_SERVICES = "VCAP_SERVICES={ \"solace-messaging\": [" + JSONString + "] }";

    load(CF_CLOUD_APP_ENV, CF_VCAP_SERVICES);

    Environment env = context.getEnvironment();

    String VCAP_APPLICATION = env.getProperty("VCAP_APPLICATION");
    assertNotNull(VCAP_APPLICATION);
    assertEquals("{}", VCAP_APPLICATION);

    String VCAP_SERVICES = env.getProperty("VCAP_SERVICES");
    assertNotNull(VCAP_SERVICES);
    assertTrue(VCAP_SERVICES.contains("solace-messaging"));

    validateBackwardsCompatibility();

    T bean = this.context.getBean(beanClass);
    assertNotNull(bean);

    if (beanClass.equals(SpringJCSMPFactoryCloudFactory.class)) {
        @SuppressWarnings("unchecked")
        SpringJCSMPFactoryCloudFactory springJCSMPFactoryCloudFactory = (SpringJCSMPFactoryCloudFactory) bean;
        assertNotNull(springJCSMPFactoryCloudFactory.getSpringJCSMPFactory());
        List<SolaceServiceCredentials> availableServices = springJCSMPFactoryCloudFactory
                .getSolaceServiceCredentials();
        assertNotNull(availableServices);
        assertEquals(1, availableServices.size());
    } else if (beanClass.equals(JCSMPProperties.class)) {
        new SpringJCSMPFactory((JCSMPProperties) bean);
    }
}

From source file:de.hska.ld.core.config.CoreBootstrap.java

@Autowired
public void init(Environment env, UserService userService, RoleService roleService) {
    List<Role> roleList = roleService.findAll();
    if (roleList == null || roleList.isEmpty()) {
        Role userRole = roleService.save(new Role(Core.ROLE_USER));
        Role adminRole = roleService.save(new Role(Core.ROLE_ADMIN));

        bootstrapPassword = env.getProperty("module.core.bootstrap.admin.password");
        if (bootstrapPassword != null && !"".equals(bootstrapPassword)) {
            try {
                userService.save(getUser("user", "user", userRole));
            } catch (Exception e) {
                //
            }/* w w  w. j  a va  2 s  . com*/
            try {
                userService.save(getUser("admin", "admin", userRole, adminRole));
            } catch (Exception e) {
                //
            }
        }
    }
}

From source file:io.fabric8.quickstarts.camel.teiid.TeiidServerAutoConfiguration.java

private String getServiceInfo(Environment environment, String serviceName, String infoType, String subType) {
    String propertyName = serviceName.toUpperCase().replace("-", "_");
    propertyName += "_SERVICE_" + infoType.toUpperCase();
    if (subType != null && subType.trim().length() > 0) {
        propertyName += "_" + subType.toUpperCase().replace("-", "_");
    }//from w ww . j  a v a2 s. com

    String info = environment.getProperty(propertyName);
    Objects.requireNonNull(info,
            "Service " + infoType + " not found in the environment (" + propertyName + ")");
    return info;
}

From source file:com.walmart.gatling.SystemConfiguration.java

/**
 * bean factory to create the agent configuration
 * @param env//from w w w . j a  v a2 s . co  m
 * @return
 */
@Bean
public AgentConfig configBuilder(Environment env) {
    AgentConfig agentConfig = new AgentConfig();

    AgentConfig.Actor actor = new AgentConfig.Actor();
    actor.setExecuterType(executerType);
    actor.setNumberOfActors(numberOfActors);
    actor.setPort(port);
    actor.setRole(role);
    agentConfig.setActor(actor);

    AgentConfig.Job jobInfo = new AgentConfig.Job();
    jobInfo.setArtifact(env.getProperty("job.artifact"));
    jobInfo.setCommand(env.getProperty("job.command"));
    jobInfo.setPath(env.getProperty("job.path"));
    jobInfo.setLogDirectory(env.getProperty("job.logDirectory"));
    jobInfo.setExitValues(new int[] { 0, 2 });
    agentConfig.setJob(jobInfo);

    AgentConfig.LogServer logServer = new AgentConfig.LogServer();
    logServer.setHostName(HostUtils.lookupIp());
    logServer.setPort(clientPort);
    agentConfig.setLogServer(logServer);

    return agentConfig;
}

From source file:com.bose.aem.spring.config.ConfigClientProperties.java

public ConfigClientProperties override(Environment environment) {
    ConfigClientProperties override = new ConfigClientProperties();
    BeanUtils.copyProperties(this, override);
    override.setName(environment.resolvePlaceholders(
            "${" + ConfigClientProperties.PREFIX + ".name:${spring.application.name:application}}"));
    if (environment.containsProperty(ConfigClientProperties.PREFIX + ".profile")) {
        override.setProfile(environment.getProperty(ConfigClientProperties.PREFIX + ".profile"));
    }/*www .  j a  va2s.co  m*/
    if (environment.containsProperty(ConfigClientProperties.PREFIX + ".label")) {
        override.setLabel(environment.getProperty(ConfigClientProperties.PREFIX + ".label"));
    }
    return override;
}

From source file:org.apache.servicecomb.config.ConfigurationSpringInitializer.java

/**
 * Try to get a name for identifying the environment.
 * @param environment the target that the name is generated for.
 * @return The generated name for the environment.
 *///  w w w . j av a2  s . c  o m
private String generateNameForEnvironment(Environment environment) {
    String environmentName = environment.getProperty("spring.config.name");
    if (!StringUtils.isEmpty(environmentName)) {
        return environmentName;
    }

    environmentName = environment.getProperty("spring.application.name");
    if (!StringUtils.isEmpty(environmentName)) {
        return environmentName;
    }

    return environment.getClass().getName() + "@" + environment.hashCode();
}