Java Code Examples for org.springframework.core.env.SimpleCommandLinePropertySource#getProperty()

The following examples show how to use org.springframework.core.env.SimpleCommandLinePropertySource#getProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenRun.java    From seed with Apache License 2.0 6 votes vote down vote up
private static String getProfile(SimpleCommandLinePropertySource source){
    if(source.containsProperty(SeedConstants.BOOT_ACTIVE_NAME)){
        log.info("读取到spring变量:{}={}", SeedConstants.BOOT_ACTIVE_NAME, source.getProperty(SeedConstants.BOOT_ACTIVE_NAME));
        return source.getProperty(SeedConstants.BOOT_ACTIVE_NAME);
    }
    if(System.getProperties().containsKey(SeedConstants.BOOT_ACTIVE_NAME)){
        log.info("读取到java变量:{}={}", SeedConstants.BOOT_ACTIVE_NAME, System.getProperty(SeedConstants.BOOT_ACTIVE_NAME));
        return System.getProperty(SeedConstants.BOOT_ACTIVE_NAME);
    }
    if(System.getenv().containsKey(SeedConstants.BOOT_ACTIVE_NAME)){
        log.info("读取到系统变量:{}={}", SeedConstants.BOOT_ACTIVE_NAME, System.getenv(SeedConstants.BOOT_ACTIVE_NAME));
        return System.getenv(SeedConstants.BOOT_ACTIVE_NAME);
    }
    log.warn("未读取到{},默认取环境:{}", SeedConstants.BOOT_ACTIVE_NAME, SeedConstants.BOOT_ACTIVE_DEFAULT_VALUE);
    return SeedConstants.BOOT_ACTIVE_DEFAULT_VALUE;
}
 
Example 2
Source File: QssRun.java    From seed with Apache License 2.0 6 votes vote down vote up
private static String getProfile(SimpleCommandLinePropertySource source){
    if(source.containsProperty(SeedConstants.BOOT_ACTIVE_NAME)){
        log.info("读取到spring变量:{}={}", SeedConstants.BOOT_ACTIVE_NAME, source.getProperty(SeedConstants.BOOT_ACTIVE_NAME));
        return source.getProperty(SeedConstants.BOOT_ACTIVE_NAME);
    }
    if(System.getProperties().containsKey(SeedConstants.BOOT_ACTIVE_NAME)){
        log.info("读取到java变量:{}={}", SeedConstants.BOOT_ACTIVE_NAME, System.getProperty(SeedConstants.BOOT_ACTIVE_NAME));
        return System.getProperty(SeedConstants.BOOT_ACTIVE_NAME);
    }
    if(System.getenv().containsKey(SeedConstants.BOOT_ACTIVE_NAME)){
        log.info("读取到系统变量:{}={}", SeedConstants.BOOT_ACTIVE_NAME, System.getenv(SeedConstants.BOOT_ACTIVE_NAME));
        return System.getenv(SeedConstants.BOOT_ACTIVE_NAME);
    }
    log.warn("未读取到{},默认取环境:{}", SeedConstants.BOOT_ACTIVE_NAME, SeedConstants.BOOT_ACTIVE_DEFAULT_VALUE);
    return SeedConstants.BOOT_ACTIVE_DEFAULT_VALUE;
}
 
Example 3
Source File: BootRun.java    From seed with Apache License 2.0 6 votes vote down vote up
private static String getProfile(SimpleCommandLinePropertySource source){
    if(source.containsProperty(SeedConstants.BOOT_ACTIVE_NAME)){
        //补充:IntelliJ IDEA运行时,如果在Run/Debug Configurations为该启动类配置Program arguments的值为"--spring.profiles.active=dev"
        //那么这里就能读取到该配置,同时控制台会打印"读取到spring变量:spring.profiles.active=dev"
        log.info("读取到spring变量:{}={}", SeedConstants.BOOT_ACTIVE_NAME, source.getProperty(SeedConstants.BOOT_ACTIVE_NAME));
        return source.getProperty(SeedConstants.BOOT_ACTIVE_NAME);
    }
    if(System.getProperties().containsKey(SeedConstants.BOOT_ACTIVE_NAME)){
        log.info("读取到java变量:{}={}", SeedConstants.BOOT_ACTIVE_NAME, System.getProperty(SeedConstants.BOOT_ACTIVE_NAME));
        return System.getProperty(SeedConstants.BOOT_ACTIVE_NAME);
    }
    if(System.getenv().containsKey(SeedConstants.BOOT_ACTIVE_NAME)){
        log.info("读取到系统变量:{}={}", SeedConstants.BOOT_ACTIVE_NAME, System.getenv(SeedConstants.BOOT_ACTIVE_NAME));
        return System.getenv(SeedConstants.BOOT_ACTIVE_NAME);
    }
    log.warn("未读取到{},默认取环境:{}", SeedConstants.BOOT_ACTIVE_NAME, SeedConstants.BOOT_ACTIVE_DEFAULT_VALUE);
    //logback-boot.xml中根据环境变量配置日志是否输出到控制台时,使用此配置
    System.setProperty(SeedConstants.BOOT_ACTIVE_NAME, SeedConstants.BOOT_ACTIVE_DEFAULT_VALUE);
    return SeedConstants.BOOT_ACTIVE_DEFAULT_VALUE;
}
 
Example 4
Source File: MppRun.java    From seed with Apache License 2.0 6 votes vote down vote up
private static String getProfile(SimpleCommandLinePropertySource source){
    if(source.containsProperty(SeedConstants.BOOT_ACTIVE_NAME)){
        log.info("读取到spring变量:{}={}", SeedConstants.BOOT_ACTIVE_NAME, source.getProperty(SeedConstants.BOOT_ACTIVE_NAME));
        return source.getProperty(SeedConstants.BOOT_ACTIVE_NAME);
    }
    if(System.getProperties().containsKey(SeedConstants.BOOT_ACTIVE_NAME)){
        log.info("读取到java变量:{}={}", SeedConstants.BOOT_ACTIVE_NAME, System.getProperty(SeedConstants.BOOT_ACTIVE_NAME));
        return System.getProperty(SeedConstants.BOOT_ACTIVE_NAME);
    }
    if(System.getenv().containsKey(SeedConstants.BOOT_ACTIVE_NAME)){
        log.info("读取到系统变量:{}={}", SeedConstants.BOOT_ACTIVE_NAME, System.getenv(SeedConstants.BOOT_ACTIVE_NAME));
        return System.getenv(SeedConstants.BOOT_ACTIVE_NAME);
    }
    log.warn("未读取到{},默认取环境:{}", SeedConstants.BOOT_ACTIVE_NAME, SeedConstants.BOOT_ACTIVE_DEFAULT_VALUE);
    return SeedConstants.BOOT_ACTIVE_DEFAULT_VALUE;
}