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:com.cisco.cta.taxii.adapter.AdapterRunnerTest.java

@Test
public void runApplication() throws Exception {
    assertTrue("PID file created", PID_FILE.isFile());
    assertTrue(AdapterRunner.ctx.isRunning());
    Environment env = AdapterRunner.ctx.getBean(Environment.class);
    assertThat(env.getProperty("foo.param"), is("argument-value"));
    exitCode = SpringApplication.exit(AdapterRunner.ctx);
    assertThat(exitCode, is(0));/*from   w  w w .  j a v a 2s .co m*/
}

From source file:hello.SwaggerConfiguration.java

@Bean
public Docket setupSwaggerApi(final Environment env) {
    return new Docket(SWAGGER_2)
            .apiInfo(new ApiInfo(env.getProperty("swagger.api.title"),
                    env.getProperty("swagger.api.description"), env.getProperty("swagger.api.version"),
                    env.getProperty("swagger.api.terms-of-service.url"),
                    env.getProperty("swagger.api.contact.email-address"),
                    env.getProperty("swagger.api.license.name"), env.getProperty("swagger.api.license.url")))
            .useDefaultResponseMessages(false).select().paths(SwaggerConfiguration::notManagement).build();
}

From source file:org.cloudfoundry.identity.uaa.login.test.DefaultIntegrationTestConfig.java

@Bean
public IntegrationTestRule integrationTestRule(@Value("${integration.test.uaa_url}") String baseUrl,
        Environment environment) {
    boolean forceIntegrationTests = environment.getProperty("forceIntegrationTests") != null;
    return new IntegrationTestRule(baseUrl, forceIntegrationTests);
}

From source file:com.folion.config.PersistenceConfiguration.java

private ProxyBucket getProxyBucket(Environment environment, String bucketName) {
    String couchbaseServersFromConfig = environment.getProperty("srv.couchbase.servers");

    List<String> servers = new ArrayList<>(Arrays.asList(couchbaseServersFromConfig.split(",")));
    Cluster cluster = CouchbaseCluster.create(servers);
    Bucket bucket = cluster.openBucket(environment.getProperty("srv.couchbase." + bucketName), 1,
            TimeUnit.DAYS);/*from   w  w  w  .  ja  v a  2  s . c om*/

    return new ProxyBucket(cluster, bucket);
}

From source file:system.AppConfiguration.java

/**
 * Actor system Singleton per ApplicationContext for this application.
 *//* w w  w  .j  a  va2  s.c om*/
@Bean
public ActorSystem actorSystem(ApplicationContext applicationContext) {
    Environment environment = applicationContext.getEnvironment();
    final String name = environment.getProperty(ActorSystemProperties.NAME);
    final Config config = environment.getProperty(ActorSystemProperties.CONFIG, Config.class);
    ActorSystem system = ActorSystem.create(name, config);
    SpringExtProvider.get(system).initialize(applicationContext);
    return system;
}

From source file:asia.gkc.vneedu.common.property.CdnProperties.java

@Autowired
public CdnProperties(@Value("${app.storage.cdn.enabled:false}") boolean cdnEnabled,
        @Value("${app.storage.cdn.bucket}") String bucket, QiniuProperties qiniuProperties,
        LocalStorageProperties localStorageProperties, Environment environment) {
    this.cdnEnabled = cdnEnabled;
    String BUCKET = environment.getProperty("VNEEDU_BUCKET");
    this.bucket = BUCKET == null ? bucket : BUCKET;
    this.qiniuProperties = qiniuProperties;
    this.localStorageProperties = localStorageProperties;
}

From source file:de.interseroh.report.webapp.SessionListener.java

@Override
public void sessionCreated(HttpSessionEvent event) {
    ApplicationContext applicationContext = getApplicationContext(event);
    Environment env = applicationContext.getEnvironment();

    String timeout = env.getProperty("session.timeout.interval");

    if (timeout == null || timeout.equals("")) {
        // Default seconds 21600 == 6 hours
        timeout = DEFAULT_TIMEOUT_INTERVAL;
    }//from w ww. j a va 2s.c o m

    event.getSession().setMaxInactiveInterval(Integer.parseInt(timeout));

    if (logger.isDebugEnabled()) {
        logger.debug("Session created, timeout: " + timeout);
    }
}

From source file:org.meruvian.yama.webapi.service.RestSignUpService.java

@Override
public void setEnvironment(Environment environment) {
    this.defaultRole = environment.getProperty("default.role");
}

From source file:example.helloworld.PropertySourceTests.java

/**
 * {@code @VaultPropertySource("secret/myapp/configuration")} will register a property
 * source and expose its properties through {@link Environment}.
 */// ww  w . ja v a 2 s .co  m
@Test
public void environmentShouldExposeVaultPropertySource() {

    Environment env = applicationContext.getEnvironment();

    assertThat(env.getProperty("configuration.key")).isEqualTo("value");
}

From source file:cf.spring.config.YamlPropertyContextInitializerTest.java

@Test
public void contextWithYamlProperties() {
    final String name = "config";

    final SpringApplication springApplication = new SpringApplication(Config.class);
    springApplication.addInitializers(new YamlPropertyContextInitializer(name, "config", "testProperties.yml"));
    try (ConfigurableApplicationContext applicationContext = (ConfigurableApplicationContext) springApplication
            .run()) {//from  ww w .  j a v a 2  s.co  m
        final YamlDocument config = applicationContext.getBean(name, YamlDocument.class);
        assertNotNull(config);
        assertEquals(config.get("foo"), "This is foo");

        final Environment environment = applicationContext.getEnvironment();
        assertEquals(environment.getProperty("foo"), "This is foo");
    }
}