org.springframework.core.env.SimpleCommandLinePropertySource Java Examples

The following examples show how to use org.springframework.core.env.SimpleCommandLinePropertySource. 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: SpringApplication.java    From spring-javaformat with Apache License 2.0 6 votes vote down vote up
/**
 * Add, remove or re-order any {@link PropertySource}s in this application's
 * environment.
 * @param environment this application's environment
 * @param args arguments passed to the {@code run} method
 * @see #configureEnvironment(ConfigurableEnvironment, String[])
 */
protected void configurePropertySources(ConfigurableEnvironment environment,
		String[] args) {
	MutablePropertySources sources = environment.getPropertySources();
	if (this.defaultProperties != null && !this.defaultProperties.isEmpty()) {
		sources.addLast(
				new MapPropertySource("defaultProperties", this.defaultProperties));
	}
	if (this.addCommandLineProperties && args.length > 0) {
		String name = CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME;
		if (sources.contains(name)) {
			PropertySource<?> source = sources.get(name);
			CompositePropertySource composite = new CompositePropertySource(name);
			composite.addPropertySource(new SimpleCommandLinePropertySource(
					"springApplicationCommandLineArgs", args));
			composite.addPropertySource(source);
			sources.replace(name, composite);
		}
		else {
			sources.addFirst(new SimpleCommandLinePropertySource(args));
		}
	}
}
 
Example #2
Source File: GpmrApp.java    From gpmr with Apache License 2.0 6 votes vote down vote up
/**
 * Main method, used to run the application.
 *
 * @param args the command line arguments
 * @throws UnknownHostException if the local host name could not be resolved into an address
 */
public static void main(String[] args) throws UnknownHostException {
    SpringApplication app = new SpringApplication(GpmrApp.class);
    SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);
    addDefaultProfile(app, source);
    Environment env = app.run(args).getEnvironment();
    log.info("\n----------------------------------------------------------\n\t" +
            "Application '{}' is running! Access URLs:\n\t" +
            "Local: \t\thttp://127.0.0.1:{}\n\t" +
            "External: \thttp://{}:{}\n----------------------------------------------------------",
        env.getProperty("spring.application.name"),
        env.getProperty("server.port"),
        InetAddress.getLocalHost().getHostAddress(),
        env.getProperty("server.port"));

}
 
Example #3
Source File: FooApp.java    From jhipster-ribbon-hystrix with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Main method, used to run the application.
 *
 * @param args the command line arguments
 * @throws UnknownHostException if the local host name could not be resolved into an address
 */
public static void main(String[] args) throws UnknownHostException {
    SpringApplication app = new SpringApplication(FooApp.class);
    SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);
    addDefaultProfile(app, source);
    Environment env = app.run(args).getEnvironment();
    log.info("\n----------------------------------------------------------\n\t" +
            "Application '{}' is running! Access URLs:\n\t" +
            "Local: \t\thttp://127.0.0.1:{}\n\t" +
            "External: \thttp://{}:{}\n----------------------------------------------------------",
        env.getProperty("spring.application.name"),
        env.getProperty("server.port"),
        InetAddress.getLocalHost().getHostAddress(),
        env.getProperty("server.port"));

    String configServerStatus = env.getProperty("configserver.status");
    log.info("\n----------------------------------------------------------\n\t" +
    "Config Server: \t{}\n----------------------------------------------------------",
        configServerStatus == null ? "Not found or not setup for this application" : configServerStatus);
}
 
Example #4
Source File: BarApp.java    From jhipster-ribbon-hystrix with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Main method, used to run the application.
 *
 * @param args the command line arguments
 * @throws UnknownHostException if the local host name could not be resolved into an address
 */
public static void main(String[] args) throws UnknownHostException {
    SpringApplication app = new SpringApplication(BarApp.class);
    SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);
    addDefaultProfile(app, source);
    Environment env = app.run(args).getEnvironment();
    log.info("\n----------------------------------------------------------\n\t" +
            "Application '{}' is running! Access URLs:\n\t" +
            "Local: \t\thttp://127.0.0.1:{}\n\t" +
            "External: \thttp://{}:{}\n----------------------------------------------------------",
        env.getProperty("spring.application.name"),
        env.getProperty("server.port"),
        InetAddress.getLocalHost().getHostAddress(),
        env.getProperty("server.port"));

    String configServerStatus = env.getProperty("configserver.status");
    log.info("\n----------------------------------------------------------\n\t" +
    "Config Server: \t{}\n----------------------------------------------------------",
        configServerStatus == null ? "Not found or not setup for this application" : configServerStatus);
}
 
Example #5
Source File: Application.java    From angularjs-springboot-bookstore with MIT License 6 votes vote down vote up
/**
 * Main method, used to run the application.
 */
public static void main(String[] args) throws UnknownHostException {
    SpringApplication app = new SpringApplication(Application.class);
    app.setShowBanner(false);
    SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);
    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"));

}
 
Example #6
Source File: GatewayApp.java    From jhipster-ribbon-hystrix with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Main method, used to run the application.
 *
 * @param args the command line arguments
 * @throws UnknownHostException if the local host name could not be resolved into an address
 */
public static void main(String[] args) throws UnknownHostException {
    SpringApplication app = new SpringApplication(GatewayApp.class);
    SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);
    addDefaultProfile(app, source);
    Environment env = app.run(args).getEnvironment();
    log.info("\n----------------------------------------------------------\n\t" +
            "Application '{}' is running! Access URLs:\n\t" +
            "Local: \t\thttp://127.0.0.1:{}\n\t" +
            "External: \thttp://{}:{}\n----------------------------------------------------------",
        env.getProperty("spring.application.name"),
        env.getProperty("server.port"),
        InetAddress.getLocalHost().getHostAddress(),
        env.getProperty("server.port"));

    String configServerStatus = env.getProperty("configserver.status");
    log.info("\n----------------------------------------------------------\n\t" +
    "Config Server: \t{}\n----------------------------------------------------------",
        configServerStatus == null ? "Not found or not setup for this application" : configServerStatus);
}
 
Example #7
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;
}
 
Example #8
Source File: Application.java    From ServiceCutter with Apache License 2.0 6 votes vote down vote up
/**
 * Main method, used to run the application.
 */
public static void main(String[] args) throws UnknownHostException {
    SpringApplication app = new SpringApplication(Application.class);
    app.setShowBanner(false);
    SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);
    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"));

}
 
Example #9
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 #10
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 #11
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 #12
Source File: Application.java    From ServiceCutter with Apache License 2.0 5 votes vote down vote up
/**
 * If no profile has been configured, set by default the "dev" profile.
 */
private static void addDefaultProfile(SpringApplication app, SimpleCommandLinePropertySource source) {
    if (!source.containsProperty("spring.profiles.active") &&
            !System.getenv().containsKey("SPRING_PROFILES_ACTIVE")) {

        app.setAdditionalProfiles(Constants.SPRING_PROFILE_DEVELOPMENT);
    }
}
 
Example #13
Source File: Application.java    From angularjs-springboot-bookstore with MIT License 5 votes vote down vote up
/**
 * If no profile has been configured, set by default the "dev" profile.
 */
private static void addDefaultProfile(SpringApplication app, SimpleCommandLinePropertySource source) {
    if (!source.containsProperty("spring.profiles.active") &&
            !System.getenv().containsKey("SPRING_PROFILES_ACTIVE")) {

        app.setAdditionalProfiles(Constants.SPRING_PROFILE_DEVELOPMENT);
    }
}
 
Example #14
Source File: MSF4JSpringApplication.java    From msf4j with Apache License 2.0 5 votes vote down vote up
protected ConfigurableApplicationContext run(boolean doRefresh, String... args) {
    ConfigurableApplicationContext context = createApplicationContext();
    if (configurationClass != null) {
        registerIfAnnotationConfigApplicationContext(context);
    } else {
        scanIfAnnotationConfigApplicationContext(context);
    }

    context.getEnvironment().getPropertySources().addFirst(new SimpleCommandLinePropertySource(args));

    if (doRefresh) {
        context.refresh();
    }
    return context;
}
 
Example #15
Source File: Application.java    From todo-spring-angular with MIT License 5 votes vote down vote up
/**
 * If no profile has been configured, set by default the "dev" profile.
 */
private static void addDefaultProfile(SpringApplication app, SimpleCommandLinePropertySource source) {
    if (!source.containsProperty("spring.profiles.active") &&
        !System.getenv().containsKey("SPRING_PROFILES_ACTIVE")) {

        app.setAdditionalProfiles(Constants.SPRING_PROFILE_DEVELOPMENT);
    }
}
 
Example #16
Source File: Application.java    From expper with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Main method, used to run the application.
 */
public static void main(String[] args) throws UnknownHostException {
    SpringApplication app = new SpringApplication(Application.class);
    SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);
    addDefaultProfile(app, source);
    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"));

}
 
Example #17
Source File: Application.java    From todo-spring-angular with MIT License 5 votes vote down vote up
/**
 * Main method, used to run the application.
 */
public static void main(String[] args) throws UnknownHostException {
    SpringApplication app = new SpringApplication(Application.class);
    SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);
    addDefaultProfile(app, source);
    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"));
}
 
Example #18
Source File: AbstractApplication.java    From springboot-multiple-dataSources with Apache License 2.0 5 votes vote down vote up
/**
 * If no profile has been configured, set by default the "dev" profile.
 */
protected static void addDefaultProfile(SpringApplication app, SimpleCommandLinePropertySource source) {
    if ((System.getProperty("spring.profiles.active") == null)
            && !source.containsProperty("spring.profiles.active")
            && !System.getenv().containsKey("SPRING_PROFILES_ACTIVE")) {
        app.setAdditionalProfiles(Constants.SPRING_PROFILE_DEVELOPMENT);
    }
}
 
Example #19
Source File: AbstractApplication.java    From springboot-multiple-dataSources with Apache License 2.0 5 votes vote down vote up
protected static void abstractMain(SpringApplication app, String[] args) throws UnknownHostException {
    SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);
    addDefaultProfile(app, source);
    //addLiquibaseScanPackages();
    staticEnv = app.run(args).getEnvironment();
    showAppInfo(staticEnv);
}
 
Example #20
Source File: Application.java    From expper with GNU General Public License v3.0 5 votes vote down vote up
/**
 * If no profile has been configured, set by default the "dev" profile.
 */
private static void addDefaultProfile(SpringApplication app, SimpleCommandLinePropertySource source) {
    if (!source.containsProperty("spring.profiles.active") &&
            !System.getenv().containsKey("SPRING_PROFILES_ACTIVE")) {

        app.setAdditionalProfiles(Constants.SPRING_PROFILE_DEVELOPMENT);
    }
}
 
Example #21
Source File: GpmrApp.java    From gpmr with Apache License 2.0 5 votes vote down vote up
/**
 * If no profile has been configured, set by default the "dev" profile.
 */
private static void addDefaultProfile(SpringApplication app, SimpleCommandLinePropertySource source) {
    if (!source.containsProperty("spring.profiles.active") &&
        !System.getenv().containsKey("SPRING_PROFILES_ACTIVE")) {

        app.setAdditionalProfiles(Constants.SPRING_PROFILE_DEVELOPMENT);
    }
}
 
Example #22
Source File: AbstractApplication.java    From huanhuan-blog with Apache License 2.0 5 votes vote down vote up
/**
 * If no profile has been configured, set by default the "dev" profile.
 */
protected static void addDefaultProfile(SpringApplication app, SimpleCommandLinePropertySource source) {
    if ((System.getProperty("spring.profiles.active") == null)
            && !source.containsProperty("spring.profiles.active")
            && !System.getenv().containsKey("SPRING_PROFILES_ACTIVE")) {
        app.setAdditionalProfiles(Constants.SPRING_PROFILE_DEVELOPMENT);
    }
}
 
Example #23
Source File: AbstractApplication.java    From huanhuan-blog with Apache License 2.0 5 votes vote down vote up
protected static void abstractMain(SpringApplication app, String[] args) throws UnknownHostException {
    SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);
    addDefaultProfile(app, source);
    //addLiquibaseScanPackages();
    staticEnv = app.run(args).getEnvironment();
    showAppInfo(staticEnv);
}
 
Example #24
Source File: FooApp.java    From jhipster-ribbon-hystrix with GNU General Public License v3.0 5 votes vote down vote up
/**
 * If no profile has been configured, set by default the "dev" profile.
 */
private static void addDefaultProfile(SpringApplication app, SimpleCommandLinePropertySource source) {
    if (!source.containsProperty("spring.profiles.active") &&
            !System.getenv().containsKey("SPRING_PROFILES_ACTIVE")) {

        app.setAdditionalProfiles(Constants.SPRING_PROFILE_DEVELOPMENT);
    }
}
 
Example #25
Source File: BarApp.java    From jhipster-ribbon-hystrix with GNU General Public License v3.0 5 votes vote down vote up
/**
 * If no profile has been configured, set by default the "dev" profile.
 */
private static void addDefaultProfile(SpringApplication app, SimpleCommandLinePropertySource source) {
    if (!source.containsProperty("spring.profiles.active") &&
            !System.getenv().containsKey("SPRING_PROFILES_ACTIVE")) {

        app.setAdditionalProfiles(Constants.SPRING_PROFILE_DEVELOPMENT);
    }
}
 
Example #26
Source File: GatewayApp.java    From jhipster-ribbon-hystrix with GNU General Public License v3.0 5 votes vote down vote up
/**
 * If no profile has been configured, set by default the "dev" profile.
 */
private static void addDefaultProfile(SpringApplication app, SimpleCommandLinePropertySource source) {
    if (!source.containsProperty("spring.profiles.active") &&
            !System.getenv().containsKey("SPRING_PROFILES_ACTIVE")) {

        app.setAdditionalProfiles(Constants.SPRING_PROFILE_DEVELOPMENT);
    }
}
 
Example #27
Source File: BootRun.java    From seed with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    //SpringApplication.run(BootRun.class, args);
    //new SpringApplicationBuilder().sources(BootRun.class).profiles(getProfile(new SimpleCommandLinePropertySource(args))).run(args);
    new SpringApplicationBuilder().sources(BootRun.class)
            .listeners(new ApplicationStartingEventListener())
            .listeners(new ApplicationEnvironmentPreparedEventListener())
            .listeners(new ApplicationPreparedEventListener())
            .listeners(new ApplicationFailedEventListener())
            .listeners(new ApplicationPidFileWriter())
            .profiles(getProfile(new SimpleCommandLinePropertySource(args)))
            .run(args);
}
 
Example #28
Source File: SwaggerBrakeMain.java    From swagger-brake with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs the CLI interface.
 * @param args the arguments
 * @return the CLI interface object
 */
public static Cli createCliInterface(String[] args) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(CliConfiguration.class);
    ConfigurableEnvironment environment = context.getEnvironment();
    environment.getPropertySources().addFirst(new SimpleCommandLinePropertySource(args));
    return context.getBean(Cli.class);
}
 
Example #29
Source File: MppRun.java    From seed with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    new SpringApplicationBuilder().sources(MppRun.class).profiles(getProfile(new SimpleCommandLinePropertySource(args))).run(args);
}
 
Example #30
Source File: QssRun.java    From seed with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    new SpringApplicationBuilder().sources(QssRun.class).profiles(getProfile(new SimpleCommandLinePropertySource(args))).run(args);
}