Close

Spring Boot - Customizing properties Examples

Spring Boot 

package com.logicbig.example;

import org.springframework.boot.SpringApplication;

import java.net.MalformedURLException;

public class CommandLineAppPropsSwitchExample {
public static void main (String[] args) throws MalformedURLException {
SpringApplication app = new SpringApplication(CustomBannerExample.class);
app.setLogStartupInfo(false);
//rename my-application.properties to application.properties
//or use a command line switch.. here we just overriding args
String[] myArgs = {"--spring.config.name=my-application"};
app.run(myArgs);
}
}

Output

---------------------
Test Banner
---------------------
Original Post




Customizing spring, setting command line switch for banner location.

package com.logicbig.example;

import org.springframework.boot.SpringApplication;

import java.net.MalformedURLException;

public class CommandLinePropSwitchExample {
public static void main (String[] args) throws MalformedURLException {

SpringApplication app = new SpringApplication(CommandLinePropSwitchExample.class);
app.setLogStartupInfo(false);
//rename resources/my-banner.txt to banner.txt
//here we are just using command line arg
String[] strings = {"--banner.location=my-banner.txt"};
app.run(strings);
}
}

Output

---------------------
Test Banner
---------------------
Original Post




package com.logicbig.example;

import org.springframework.boot.SpringApplication;

import java.net.MalformedURLException;
import java.util.Properties;

public class SetDefaultPropertiesExample {
public static void main (String[] args) throws MalformedURLException {
SpringApplication app = new SpringApplication(CustomBannerExample.class);
Properties p = new Properties();
p.setProperty("banner.location", "my-banner.txt");
p.setProperty("logging.level.org.springframework", "DEBUG");
app.setDefaultProperties(p);
app.run(args);
}
}

Output

2017-05-01 16:10:03.045 DEBUG 14020 --- [sExample.main()] .b.l.ClasspathLoggingApplicationListener : Application started with classpath: [file:/D:/LogicBig/example-projects/spring-boot/boot-startup-customizing/target/classes/, file:/C:/Users/Joe/.m2/repository/org/springframework/boot/spring-boot-starter/1.4.2.RELEASE/spring-boot-starter-1.4.2.RELEASE.jar, file:/C:/Users/Joe/.m2/repository/org/springframework/boot/spring-boot/1.4.2.RELEASE/spring-boot-1.4.2.RELEASE.jar, file:/C:/Users/Joe/.m2/repository/org/springframework/spring-context/4.3.4.RELEASE/spring-context-4.3.4.RELEASE.jar, file:/C:/Users/Joe/.m2/repository/org/springframework/spring-aop/4.3.4.RELEASE/spring-aop-4.3.4.RELEASE.jar, file:/C:/Users/Joe/.m2/repository/org/springframework/spring-beans/4.3.4.RELEASE/spring-beans-4.3.4.RELEASE.jar, file:/C:/Users/Joe/.m2/repository/org/springframework/spring-expression/4.3.4.RELEASE/spring-expression-4.3.4.RELEASE.jar, file:/C:/Users/Joe/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/1.4.2.RELEASE/spring-boot-autoconfigure-1.4.2.RELEASE.jar, file:/C:/Users/Joe/.m2/repository/org/springframework/boot/spring-boot-starter-logging/1.4.2.RELEASE/spring-boot-starter-logging-1.4.2.RELEASE.jar, file:/C:/Users/Joe/.m2/repository/ch/qos/logback/logback-classic/1.1.7/logback-classic-1.1.7.jar, file:/C:/Users/Joe/.m2/repository/ch/qos/logback/logback-core/1.1.7/logback-core-1.1.7.jar, file:/C:/Users/Joe/.m2/repository/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar, file:/C:/Users/Joe/.m2/repository/org/slf4j/jcl-over-slf4j/1.7.21/jcl-over-slf4j-1.7.21.jar, file:/C:/Users/Joe/.m2/repository/org/slf4j/jul-to-slf4j/1.7.21/jul-to-slf4j-1.7.21.jar, file:/C:/Users/Joe/.m2/repository/org/slf4j/log4j-over-slf4j/1.7.21/log4j-over-slf4j-1.7.21.jar, file:/C:/Users/Joe/.m2/repository/org/springframework/spring-core/4.3.4.RELEASE/spring-core-4.3.4.RELEASE.jar, file:/C:/Users/Joe/.m2/repository/org/yaml/snakeyaml/1.17/snakeyaml-1.17.jar]
2017-05-01 16:10:03.049 DEBUG 14020 --- [sExample.main()] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'context.listener.classes' in any property source
2017-05-01 16:10:03.051 DEBUG 14020 --- [sExample.main()] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'banner.image.location' in any property source
2017-05-01 16:10:03.052 DEBUG 14020 --- [sExample.main()] o.s.c.e.PropertySourcesPropertyResolver : Found key 'banner.location' in [defaultProperties] with type [String]
2017-05-01 16:10:03.055 DEBUG 14020 --- [sExample.main()] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'banner.charset' in any property source
2017-05-01 16:10:03.057 DEBUG 14020 --- [sExample.main()] o.s.core.env.MutablePropertySources : Adding [version] PropertySource with lowest search precedence
2017-05-01 16:10:03.058 DEBUG 14020 --- [sExample.main()] o.s.core.env.MutablePropertySources : Adding [ansi] PropertySource with highest search precedence
2017-05-01 16:10:03.059 DEBUG 14020 --- [sExample.main()] o.s.core.env.MutablePropertySources : Adding [title] PropertySource with highest search precedence
---------------------
Test Banner
---------------------
2017-05-01 16:10:03.179 DEBUG 14020 --- [sExample.main()] o.s.core.env.StandardEnvironment : Adding [systemProperties] PropertySource with lowest search precedence
2017-05-01 16:10:03.180 DEBUG 14020 --- [sExample.main()] o.s.core.env.StandardEnvironment : Adding [systemEnvironment] PropertySource with lowest search precedence
2017-05-01 16:10:03.180 DEBUG 14020 --- [sExample.main()] o.s.core.env.StandardEnvironment : Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
2017-05-01 16:10:03.214 DEBUG 14020 --- [sExample.main()] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'context.initializer.classes' in any property source
2017-05-01 16:10:03.214 DEBUG 14020 --- [sExample.main()] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'spring.config.name:application' in any property source
2017-05-01 16:10:03.214 DEBUG 14020 --- [sExample.main()] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'spring.config.name' in any property source
2017-05-01 16:10:03.214 DEBUG 14020 --- [sExample.main()] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'vcap.application.name:application' in any property source
2017-05-01 16:10:03.214 DEBUG 14020 --- [sExample.main()] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'vcap.application.name' in any property source
2017-05-01 16:10:03.214 DEBUG 14020 --- [sExample.main()] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'spring.application.name:application' in any property source
2017-05-01 16:10:03.214 DEBUG 14020 --- [sExample.main()] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'spring.application.name' in any property source
2017-05-01 16:10:03.215 DEBUG 14020 --- [sExample.main()] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'PORT:null' in any property source
2017-05-01 16:10:03.215 DEBUG 14020 --- [sExample.main()] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'PORT' in any property source
2017-05-01 16:10:03.215 DEBUG 14020 --- [sExample.main()] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'server.port:null' in any property source
2017-05-01 16:10:03.215 DEBUG 14020 --- [sExample.main()] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'server.port' in any property source
2017-05-01 16:10:03.215 DEBUG 14020 --- [sExample.main()] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'spring.application.index:null' in any property source
2017-05-01 16:10:03.215 DEBUG 14020 --- [sExample.main()] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'spring.application.index' in any property source
2017-05-01 16:10:03.215 DEBUG 14020 --- [sExample.main()] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'vcap.application.instance_index:null' in any property source
2017-05-01 16:10:03.215 DEBUG 14020 --- [sExample.main()] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'vcap.application.instance_index' in any property source
2017-05-01 16:10:03.215 DEBUG 14020 --- [sExample.main()] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'spring.profiles.active' in any property source
2017-05-01 16:10:03.219 DEBUG 14020 --- [sExample.main()] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'autoConfigurationReport'
2017-05-01 16:10:03.225 INFO 14020 --- [sExample.main()] c.l.example.SetDefaultPropertiesExample : Starting SetDefaultPropertiesExample on JoeMsi with PID 14020 (D:\LogicBig\example-projects\spring-boot\boot-startup-customizing\target\classes started by Joe in D:\LogicBig\example-projects\spring-boot\boot-startup-customizing)
2017-05-01 16:10:03.225 DEBUG 14020 --- [sExample.main()] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'spring.profiles.active' in any property source
2017-05-01 16:10:03.225 DEBUG 14020 --- [sExample.main()] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'spring.profiles.default' in any property source
2017-05-01 16:10:03.225 INFO 14020 --- [sExample.main()] c.l.example.SetDefaultPropertiesExample : No active profile set, falling back to default profiles: default
2017-05-01 16:10:03.226 DEBUG 14020 --- [sExample.main()] o.s.boot.SpringApplication : Loading source class com.logicbig.example.CustomBannerExample
2017-05-01 16:10:03.282 DEBUG 14020 --- [sExample.main()] o.s.core.env.StandardEnvironment : Removing [applicationConfigurationProperties] PropertySource
2017-05-01 16:10:03.282 DEBUG 14020 --- [sExample.main()] o.s.core.env.StandardEnvironment : Removing [defaultProperties] PropertySource
2017-05-01 16:10:03.282 DEBUG 14020 --- [sExample.main()] o.s.core.env.StandardEnvironment : Adding [defaultProperties] PropertySource with lowest search precedence
2017-05-01 16:10:03.303 DEBUG 14020 --- [sExample.main()] o.s.b.f.s.DefaultListableBeanFactory : Creating shared instance of singleton bean 'customBannerExample'
2017-05-01 16:10:03.303 DEBUG 14020 --- [sExample.main()] o.s.b.f.s.DefaultListableBeanFactory : Creating instance of bean 'customBannerExample'
2017-05-01 16:10:03.303 DEBUG 14020 --- [sExample.main()] o.s.b.f.s.DefaultListableBeanFactory : Eagerly caching bean 'customBannerExample' to allow for resolving potential circular references
2017-05-01 16:10:03.304 DEBUG 14020 --- [sExample.main()] o.s.b.f.s.DefaultListableBeanFactory : Finished creating instance of bean 'customBannerExample'
2017-05-01 16:10:03.323 DEBUG 14020 --- [sExample.main()] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'lifecycleProcessor'
2017-05-01 16:10:03.326 DEBUG 14020 --- [sExample.main()] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'spring.liveBeansView.mbeanDomain' in any property source
2017-05-01 16:10:03.330 INFO 14020 --- [sExample.main()] c.l.example.SetDefaultPropertiesExample : Started SetDefaultPropertiesExample in 0.425 seconds (JVM running for 2.442)
2017-05-01 16:10:03.416 DEBUG 14020 --- [ Thread-1] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'lifecycleProcessor'
Original Post




package com.logicbig.example;

import org.springframework.boot.SpringApplication;

import java.net.MalformedURLException;

public class TurnOffLogsExample {
public static void main (String[] args) throws MalformedURLException {
SpringApplication app = new SpringApplication(TurnOffLogsExample.class);
app.setLogStartupInfo(false);
app.run(args);
}
}

Output


. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.4.2.RELEASE)
Original Post




See Also