use of org.springframework.core.env.SimpleCommandLinePropertySource in project spring-boot by spring-projects.
the class SpringApplication method configurePropertySources.
/**
* 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 (!CollectionUtils.isEmpty(this.defaultProperties)) {
DefaultPropertiesPropertySource.addOrMerge(this.defaultProperties, sources);
}
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));
}
}
}
use of org.springframework.core.env.SimpleCommandLinePropertySource in project spring-boot by spring-projects.
the class ConfigFileApplicationListenerTests method commandLineWins.
@Test
public void commandLineWins() throws Exception {
this.environment.getPropertySources().addFirst(new SimpleCommandLinePropertySource("--the.property=fromcommandline"));
this.initializer.setSearchNames("testproperties");
this.initializer.postProcessEnvironment(this.environment, this.application);
String property = this.environment.getProperty("the.property");
assertThat(property).isEqualTo("fromcommandline");
}
use of org.springframework.core.env.SimpleCommandLinePropertySource in project nixmash-blog by mintster.
the class BatchLauncher method main.
public static void main(String[] args) throws Exception {
PropertySource commandLineProperties = new SimpleCommandLinePropertySource(args);
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.getEnvironment().getPropertySources().addFirst(commandLineProperties);
context.register(ApplicationConfiguration.class);
context.refresh();
}
use of org.springframework.core.env.SimpleCommandLinePropertySource in project mica2 by obiba.
the class Application method main.
/**
* Main method, used to run the application.
* <p/>
* To run the application with hot reload enabled, add the following arguments to your JVM:
* "-javaagent:spring_loaded/springloaded-jhipster.jar -noverify -Dspringloaded=plugins=io.github.jhipster.loaded.instrument.JHipsterLoadtimeInstrumentationPlugin"
*/
public static void main(String... args) {
checkSystemProperty("MICA_HOME");
SpringApplicationBuilder app = new SpringApplicationBuilder(Application.class).bannerMode(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);
app.run(args);
}
use of org.springframework.core.env.SimpleCommandLinePropertySource in project spring-boot by spring-projects.
the class ConfigDataEnvironmentPostProcessorIntegrationTests method runWhenHasCommandLinePropertiesLoadsWithCommandLineTakingPrecedence.
@Test
void runWhenHasCommandLinePropertiesLoadsWithCommandLineTakingPrecedence() {
StandardEnvironment environment = new StandardEnvironment();
environment.getPropertySources().addFirst(new SimpleCommandLinePropertySource("--the.property=fromcommandline"));
this.application.setEnvironment(environment);
ConfigurableApplicationContext context = this.application.run("--spring.config.name=testproperties");
String property = context.getEnvironment().getProperty("the.property");
assertThat(property).isEqualTo("fromcommandline");
}
Aggregations