Package org.springframework.core.env

Examples of org.springframework.core.env.SimpleCommandLinePropertySource


     */
    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(Application.class);
        app.setShowBanner(false);

        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);

View Full Code Here


  public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
    if (event.getArgs().length == 0) {
      // If there are no arguments, create cmdLineArgs property source here. This would at least hold the default
      // command line options.
      if (event.getEnvironment().getPropertySources().get(COMMAND_LINE_PROPERTY_SOURCE_NAME) == null) {
        event.getEnvironment().getPropertySources().addFirst(new SimpleCommandLinePropertySource());
      }
    }
    CmdLineParser parser = null;
    try {
      environmentHolder.set(event.getEnvironment());
View Full Code Here

    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(name
            + "-" + args.hashCode(), args));
        composite.addPropertySource(source);
        sources.replace(name, composite);
      }
      else {
        sources.addFirst(new SimpleCommandLinePropertySource(args));
      }
    }
  }
View Full Code Here

  }

  @Test
  public void commandLineWins() throws Exception {
    this.environment.getPropertySources().addFirst(
        new SimpleCommandLinePropertySource("--the.property=fromcommandline"));
    this.initializer.setSearchNames("testproperties");
    this.initializer.onApplicationEvent(this.event);
    String property = this.environment.getProperty("the.property");
    assertThat(property, equalTo("fromcommandline"));
  }
View Full Code Here

TOP

Related Classes of org.springframework.core.env.SimpleCommandLinePropertySource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.