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:SpringInAction4Edition.MainApp.java

public static void main(String[] args) {

    ApplicationContext context = new AnnotationConfigApplicationContext(CDConfig.class);

    Environment env = context.getEnvironment();
    System.err.println("environment : ime : " + env.getProperty("ime"));
    System.err.println("environment : prezime : " + env.getProperty("prezime"));

    KutijaCD cd_ovi = context.getBean(KutijaCD.class);
    CDPlayer cDPlayer = context.getBean(CDPlayer.class);

    cd_ovi.getCds().stream().forEach((cd) -> {
        cd.play();/* w  ww .  j a va  2  s.c o  m*/
    });

    cDPlayer.getCd();
    System.err.println("BEAN DEF NAMES : " + Arrays.toString(context.getBeanDefinitionNames()));
}

From source file:com.infinitechaos.vpcviewer.Application.java

public static void main(String[] args) throws UnknownHostException {
    SpringApplication app = new SpringApplication(Application.class);
    app.setShowBanner(false);//from   ww  w .ja v  a 2 s.c  om

    Environment env = app.run(args).getEnvironment();
    log.info(
            "Access URLs:\n----------------------------------------------------------\n\t"
                    + "Local: \t\thttp://127.0.0.1:{}\n\t"
                    + "External: \thttp://{}:{}\n----------------------------------------------------------",
            env.getProperty("server.port"), InetAddress.getLocalHost().getHostAddress(),
            env.getProperty("server.port"));

}

From source file:fi.helsinki.opintoni.Application.java

/**
 * Main method, used to run the application.
 *///  ww  w .  j a v a 2  s.  c  om
public static void main(String[] args) throws UnknownHostException {
    SpringApplication app = new SpringApplication(Application.class);
    app.setBannerMode(Banner.Mode.OFF);

    SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);

    // Check if the selected profile has been set as argument.
    // if not the development profile will be added
    addDefaultProfile(app, source);
    addLiquibaseScanPackages();
    Environment env = app.run(args).getEnvironment();
    log.info(
            "Access URLs:\n----------------------------------------------------------\n\t"
                    + "Local: \t\thttp://127.0.0.1:{}\n\t"
                    + "External: \thttp://{}:{}\n----------------------------------------------------------",
            env.getProperty("server.port"), InetAddress.getLocalHost().getHostAddress(),
            env.getProperty("server.port"));

}

From source file:org.aksw.simba.tapioca.server.Config.java

public static @Bean BLEngine createBLEngine(Environment env) {
    return BLEngine.createEngine(new File(env.getProperty(MODEL_FOLDER_PROPERTY_KEY)),
            new File(env.getProperty(META_DATA_FILE_PROEPRTY_KEY)));
}

From source file:com.github.ferstl.spring.jdbc.oracle.dsconfig.PoolProperties.java

public static Properties createFromEnvironment(Environment env) {
    Properties props = new Properties();
    props.setProperty("url", env.getProperty("db.url"));
    props.setProperty("username", env.getProperty("db.username"));
    props.setProperty("password", env.getProperty("db.password"));
    props.setProperty("defaultAutoCommit ", env.getProperty("db.defaultAutoCommit"));

    props.setProperty("driverClassName", env.getProperty("driverClassName"));
    props.setProperty("maxActive", env.getProperty("maxActive"));
    props.setProperty("maxIdle", env.getProperty("maxIdle"));
    props.setProperty("minIdle", env.getProperty("minIdle"));
    props.setProperty("initialSize", env.getProperty("initialSize"));

    return props;
}

From source file:com.netflix.genie.agent.cli.UserConsole.java

/**
 * Load and print the Spring banner (if one is configured) to UserConsole.
 *
 * @param environment the Spring environment
 *//*  www.  jav  a2  s .  c om*/
static void printBanner(final Environment environment) {
    try {
        final String bannerLocation = environment.getProperty(BANNER_LOCATION_SPRING_PROPERTY_KEY);
        if (StringUtils.isNotBlank(bannerLocation)) {
            final ResourceLoader resourceLoader = new DefaultResourceLoader();
            final Resource resource = resourceLoader.getResource(bannerLocation);
            if (resource.exists()) {
                final String banner = StreamUtils.copyToString(resource.getInputStream(),
                        environment.getProperty(BANNER_CHARSET_SPRING_PROPERTY_KEY, Charset.class,
                                StandardCharsets.UTF_8));
                UserConsole.getLogger().info(banner);
            }
        }
    } catch (final Throwable t) {
        System.err.println("Failed to print banner: " + t.getMessage());
        t.printStackTrace(System.err);
    }
}

From source file:org.aksw.simba.tapioca.server.Config.java

public static @Bean TMEngine createEngine(Environment env,
        WorkerBasedLabelRetrievingDocumentSupplierDecorator cachingLabelRetriever) {
    return TMEngine.createEngine(cachingLabelRetriever, new File(env.getProperty(MODEL_FOLDER_PROPERTY_KEY)),
            new File(env.getProperty(META_DATA_FILE_PROEPRTY_KEY)));
}

From source file:com.ethercamp.harmony.service.BlockchainConsts.java

/**
 * Return pair of name and explorer url.
 *//*from  w w  w .j  a v a2  s. com*/
public static Pair<String, Optional<String>> getNetworkInfo(Environment env, String genesisHash) {
    final String networkNameKey = String.format("network.%s.networkName", genesisHash);
    final String explorerUrlKey = String.format("network.%s.explorerUrl", genesisHash);

    return Optional.ofNullable(env.getProperty(networkNameKey))
            .map(name -> Pair.of(name, Optional.ofNullable(env.getProperty(explorerUrlKey))))
            .orElse(Pair.of("Unknown network", Optional.empty()));
}

From source file:io.lavagna.config.DataSourceConfig.java

private static void urlAndCredentials(HikariDataSource dataSource, Environment env) {
    dataSource.setJdbcUrl(env.getRequiredProperty("datasource.url"));
    dataSource.setUsername(env.getRequiredProperty("datasource.username"));
    dataSource.setPassword(/*from   w w w  . ja  v  a 2  s  .c  o  m*/
            env.getProperty("datasource.password") != null ? env.getProperty("datasource.password") : "");
}

From source file:com.stormpath.spring.boot.examples.config.Orgs.java

@Autowired
public Orgs(Environment env) {
    USER = env.getProperty("stormpath.authorized.org.user");
    ADMIN = env.getProperty("stormpath.authorized.org.admin");
}