<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
<div style="font-family: calibri, sans-serif; font-size: 12pt;">Hello friends!!! Once again lets us discuss one of the important topics for spring boot is customizing spring boot autoconfiguration. As all we know that  ;Freedom of choice is an awesome thing. If you like PIZZA so you have many choices to select your favorite PIZZA like PAN PIZZA, PIZZA with cheese bust, pizza with different different tops yummy :). Now friends please come to our discussion, here we’re going to look at two ways to influence auto-configuration: <b>explicit configuration overrides</b> and <b>fine-grained configuration with properties</b>. </div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">
<div align='center' id="ads-id"></div>
</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;"><b>Overriding auto-configured beans</b></div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">Spring Boot auto-configuration attempts to automatically configure your Spring application based on the jar dependencies that you have added. If you can get what you need without it then why would you do extra work, writing and maintaining extra configuration code, but sometimes there are many cases Spring Boot auto configuration is not good enough. For example one of the cases is when you’re applying security to your application. Security in your application is one of major concern so it is not single fit for all because there are decisions around application security that Spring Boot has no business making for you even though Spring Boot provides auto configuration for some basic spring security things.</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">
</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;"><b>For securing the application:</b></div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">Just adding Spring Security Starter to add spring security auto configuration to the application. In gradle add following line to <b>build.gradle</b> file.</div>
<pre class="highlight" style="font-family: calibri, sans-serif; font-size: 12pt;">compile("org.springframework.boot:spring-boot-starter-security")
</pre>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">In <b>Maven </b>add following dependency for spring security starter.</div>
<pre class="highlight" style="font-family: calibri, sans-serif; font-size: 12pt;"><;dependency>;
<;groupId>;org.springframework.boot<;/groupId>;
<;artifactId>;spring-boot-starter-security<;/artifactId>;
<;/dependency>;
</pre>
<div style="font-family: calibri, sans-serif; font-size: 12pt;"></div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">That’s it! Rebuild your application and run it. It’s now a secure web application! The security starter adds Spring Security to the application’s classpath. With Spring Security on the classpath, auto-configuration kicks in and a very basic Spring Security setup is created. When open this application browser basic authentication is needed then user name is “user” and password is printed in logs.</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">
</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;"><b>Custom security configuration in the application</b></div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">Basic default configuration probably is not fit for your application because unlike authentication page and password is printed in the logs. That is why you will prefer customized security configuration in the application. For overriding default spring boot auto configuration just writing explicit XML based or Java based configuration in the application this means writing a configuration class that extends <b>WebSecurityConfigurerAdapter</b>.</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">
</div>
<pre class="highlight" style="font-family: calibri, sans-serif; font-size: 12pt;">@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
 @Autowired
 UserRepository userRepository;
 
 @Override
 protected void configure(HttpSecurity http) throws Exception {
 http
 .authorizeRequests()
 .antMatchers("/").access("hasRole(ADMIN)")
 .antMatchers("/**").permitAll()
 .and()
 .formLogin()
 .loginPage("/login")
 .failureUrl("/login?error=true");
 }
 @Override
 protected void configure(
 AuthenticationManagerBuilder auth) throws Exception {
 auth
 .userDetailsService(new UserDetailsService() {
 @Override
 public UserDetails loadUserByUsername(String username)
 throws UsernameNotFoundException {
 return userRepository.findUserName(username);
 }
 });
 }
}
</pre>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">
</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;"><b>SecurityConfig </b>is a very basic Spring Security configuration. Even so, it does a lot of what we need to customize security of the application.</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">
</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;"><b>Configuring with external properties</b></div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">Spring Boot allows you to externalize your configuration so you can work with the same application code in different environments. You can use properties files, YAML files, environment variables, Java system properties, JNDI and command-line arguments to externalize configuration. Spring Boot offers over 300 properties for auto configuration of beans in the application.</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">
</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">Let’s see one of property when you start the application one banner is printed at log screen. So you can disable that banner by setting property spring.main.show-banner to false. </div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">
</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">There are following ways to setting up this property when we run the application</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">
</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;"><b>Command Line Parameters:</b></div>
<pre class="highlight" style="font-family: calibri, sans-serif; font-size: 12pt;">$ java -jar myapp-0.0.1-SNAPSHOT.jar --spring.main.show-banner=false
</pre>
<div style="font-family: calibri, sans-serif; font-size: 12pt;"><b><br />
</b></div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;"><b>Setting in “application.properties” property file:</b></div>
<pre class="highlight" style="font-family: calibri, sans-serif; font-size: 12pt;">spring.main.show-banner=false
</pre>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">
</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;"><b>Create a YAML file named “application.yml”:</b></div>
<pre class="highlight" style="font-family: calibri, sans-serif; font-size: 12pt;">spring:
 main:
 show-banner: false
</pre>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">
</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;"><b>Setting property as an environment variable:</b></div>
<pre class="highlight" style="font-family: calibri, sans-serif; font-size: 12pt;">$ export spring_main_show_banner=false
</pre>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">
</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;"><b>Note:</b> the use of underscores instead of periods and dashes, as required for environment variable names.</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">
</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">There are, in fact, several ways to set properties for a Spring Boot application. ;Spring Boot uses a very particular PropertySource order that is designed to allow sensible overriding of values. Properties are considered in the following order:</div>
<ol>
<li style="font-family: calibri, sans-serif; font-size: 12pt;"><b>@TestPropertySource</b> annotations on your tests.</li>
<li style="font-family: calibri, sans-serif; font-size: 12pt;">Command line arguments.</li>
<li style="font-family: calibri, sans-serif; font-size: 12pt;">Properties from <b>SPRING_APPLICATION_JSON </b>(inline JSON embedded in an environment variable or system property)</li>
<li style="font-family: calibri, sans-serif; font-size: 12pt;"><b>ServletConfig </b>init parameters.</li>
<li style="font-family: calibri, sans-serif; font-size: 12pt;"><b>ServletContext </b>init parameters.</li>
<li style="font-family: calibri, sans-serif; font-size: 12pt;"><b>JNDI </b>attributes from <b>java:comp/env</b>.</li>
<li style="font-family: calibri, sans-serif; font-size: 12pt;">Java System properties (<b>System.getProperties()</b>).</li>
<li style="font-family: calibri, sans-serif; font-size: 12pt;">OS environment variables.</li>
<li style="font-family: calibri, sans-serif; font-size: 12pt;">A <b>RandomValuePropertySource </b>that only has properties in <b>random.*</b>.</li>
<li style="font-family: calibri, sans-serif; font-size: 12pt;">Profile-specific application properties outside of your packaged jar (<b>application-{profile}.properties</b> and <b>YAML </b>variants)</li>
<li style="font-family: calibri, sans-serif; font-size: 12pt;">Profile-specific application properties packaged inside your jar (<b>application-{profile}.properties </b>and <b>YAML </b>variants)</li>
<li style="font-family: calibri, sans-serif; font-size: 12pt;">Application properties outside of your packaged jar (<b>application.properties</b> and <b>YAML </b>variants).</li>
<li style="font-family: calibri, sans-serif; font-size: 12pt;">Application properties packaged inside your jar (<b>application.properties</b> and <b>YAML </b>variants).</li>
<li style="font-family: calibri, sans-serif; font-size: 12pt;"><b>@PropertySource </b>annotations on your<b> @Configuration </b>classes.</li>
<li style="font-family: calibri, sans-serif; font-size: 12pt;">Default properties (specified using <b>SpringApplication.setDefaultProperties</b>)</li>
</ol>
<div style="font-family: calibri, sans-serif;">
<div style="font-family: calibri, sans-serif; font-size: 12pt;">As for the <b>application.properties</b> and <b>application.yml </b>files, they can reside in any of four locations:</div>
<ol style="font-family: calibri, sans-serif; font-size: 12pt;">
<li><b>Externally</b>, in a <b>/config</b> subdirectory of the directory from which the application is run</li>
<li><b>Externally</b>, in the directory from which the application is run</li>
<li><b>Internally</b>, in a package named “<b>config</b>”</li>
<li><b>Internally</b>, at the root of the <b>classpath</b></li>
</ol>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">
</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">Again, this list is in order of precedence. That is, an <b>application.properties</b> file in a <b>/config</b> subdirectory will override the same properties set in an <b>application.properties</b> file in the application’s <b>classpath</b>.</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">
</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">Also, I’ve found that if you have both <b>application.properties</b> and <b>application.yml </b>side by side at the same level of precedence, <b>properties </b>in <b>application.yml</b> will override those in <b>application.properties</b>.</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">
</div>
<div style="font-family: calibri, sans-serif;"><b>Auto-configuration</b></div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">Spring Boot auto-configuration attempts to automatically configure your Spring application based on the jar dependencies that you have added. You should only ever add one <b>@EnableAutoConfiguration </b>annotation.</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;"><b><br />
</b></div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;"><b>Gradually replacing auto-configuration</b></div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">Auto-configuration is noninvasive, at any point you can start to define your own configuration to replace specific parts of the auto-configuration. For example, if you add your own DataSource bean, the default embedded database support will back away.</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;">
</div>
<div style="font-family: calibri, sans-serif; font-size: 12pt;"><b>Disabling specific auto-configuration</b></div>
<div style="font-family: calibri, sans-serif; font-size: 12.5pt;"><b>1. DISABLING TEMPLATE CACHING</b></div>
<div style="font-family: calibri, sans-serif; font-size: 12.5pt;">Thymeleaf templates are cached by default that is why changes is never replicate unless you restart the application. You can disable Thymeleaf template caching by setting <b>spring.thymeleaf.cache</b> to <b>false</b>.</div>
<div style="font-family: calibri, sans-serif;"><b>Using command-line argument:</b></div>
<pre class="highlight" style="font-family: calibri, sans-serif;">$ java -jar myapp-0.0.1-SNAPSHOT.jar --spring.thymeleaf.cache=false
</pre>
<div style="font-family: calibri, sans-serif; font-size: 12.5pt;"><b>Using application.yml file</b></div>
<pre class="highlight" style="font-family: calibri, sans-serif;">spring:
 thymeleaf:
 cache: false
</pre>
<div style="font-family: calibri, sans-serif; font-size: 12.5pt;">You’ll want to make sure that this <b>application.yml</b> file doesn’t follow the application into production.</div>
<div style="font-family: calibri, sans-serif;"><b>Using environment variable:</b></div>
<pre class="highlight" style="font-family: calibri, sans-serif;">$ export spring_thymeleaf_cache=false
</pre>
<div style="font-family: calibri, sans-serif; font-size: 12.5pt;">Others template caching can be turned off for Spring Boot’s other supported template options by setting these properties:</div>
<ul style="font-family: calibri, sans-serif;">
<li>spring.freemarker.cache (Freemarker)</li>
<li>spring.groovy.template.cache (Groovy templates)</li>
<li>spring.velocity.cache (Velocity)</li>
</ul>
<div style="font-family: calibri, sans-serif; font-size: 12.5pt;"><b>2. CONFIGURING THE EMBEDDED SERVER</b></div>
<div style="font-family: calibri, sans-serif; font-size: 12.5pt;">By default embedded server for spring boot application is <b>tomcat </b>with port <b>8080</b>. It is fine in case of single application running but it will be become problem in case run multiple applications simultaneously. If all of the applications try to start a Tomcat server on the same port, there’ll be port collisions starting with the second application.</div>
<div style="font-family: calibri, sans-serif; font-size: 12.5pt;">
</div>
<div style="font-family: calibri, sans-serif; font-size: 12.5pt;">So to prevent these collisions of port we need to do is set the <b>server.port</b> property.</div>
<div style="font-family: calibri, sans-serif; font-size: 12.5pt;">
</div>
<div style="font-family: calibri, sans-serif; font-size: 12.5pt;">If this is a one-time change, it’s easy enough to do this as a <b>command-line argument</b>:</div>
<pre class="highlight" style="font-family: calibri, sans-serif;">$ java -jar myapp-0.0.1-SNAPSHOT.jar --server.port=8181
</pre>
<div style="font-family: calibri, sans-serif; font-size: 12.5pt;">For permanent port change use <b>application.yml:</b></div>
<pre class="highlight" style="font-family: calibri, sans-serif;">server:
 port: 8000
</pre>
<div style="font-family: calibri, sans-serif; font-size: 12.5pt;"><b>3. CONFIGURING LOGGING</b></div>
<div style="font-family: calibri, sans-serif; font-size: 12.5pt;">By default, Spring Boot configures logging via Logback (http://logback.qos.ch) to log to the console at INFO level.</div>
<div style="font-family: calibri, sans-serif; font-size: 12.5pt;">
</div>
<div style="font-family: calibri, sans-serif; font-size: 12.5pt;">For <b>Maven builds</b>, you can exclude Logback by excluding the default logging starter transitively resolved by the root starter dependency:</div>
<pre class="highlight" style="font-family: calibri, sans-serif;"><;dependency>;
<;groupId>;org.springframework.boot<;/groupId>;
<;artifactId>;spring-boot-starter<;/artifactId>;
<;exclusions>;
<;exclusion>;
<;groupId>;org.springframework.boot<;/groupId>;
<;artifactId>;spring-boot-starter-logging<;/artifactId>;
<;/exclusion>;
<;/exclusions>;
<;/dependency>;
</pre>
<div style="font-family: calibri, sans-serif; font-size: 12.5pt;">In <b>Gradle</b>, it’s easiest to place the exclusion under the configurations section:</div>
<pre class="highlight" style="font-family: calibri, sans-serif;">configurations {
all*.exclude group:'org.springframework.boot',
module:'spring-boot-starter-logging'
}
</pre>
<div style="font-family: calibri, sans-serif; font-size: 12.5pt;">With the default logging starter excluded, you can now include the starter for the logging implementation you’d rather use. With a <b>Maven </b>build you can add Log4j like this: </div>
<pre class="highlight" style="font-family: calibri, sans-serif;"><;dependency>;
<;groupId>;org.springframework.boot<;/groupId>;
<;artifactId>;spring-boot-starter-log4j<;/artifactId>;
<;/dependency>;
</pre>
<div style="font-family: calibri, sans-serif; font-size: 12.5pt;">In a <b>Gradle </b>build you can add Log4j like this:</div>
<pre class="highlight" style="font-family: calibri, sans-serif;">compile("org.springframework.boot:spring-boot-starter-log4j")
</pre>
<div style="font-family: calibri, sans-serif; font-size: 12.5pt;">For full control over the logging configuration, you can create a logback.xml file at the root of the classpath (in src/main/resources). Here’s an example of a simple logback.xml file you might use:</div>
<pre class="highlight"><;configuration>;
<;appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">;
<;encoder>;
<;pattern>;
%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
<;/pattern>;
<;/encoder>;
<;/appender>;
<;logger name="root" level="INFO"/>;
<;root level="INFO">;
<;appender-ref ref="STDOUT" />;
<;/root>;
<;/configuration>;
</pre>
<div style="font-family: calibri, sans-serif; font-size: 12.5pt;">To set the logging levels, you create properties that are prefixed with <b>logging.level,</b> followed by the name of the logger for which you want to set the logging level.<br />
<b>application.yml:</b></p>
<pre class="highlight">logging:
 level:
 root: WARN
 org:
 springframework:
 security: DEBUG

</pre>
<p>
Now suppose that you want to write the log entries to a file named <b>MyApp.log</b> at <b>/opt/logs/</b>. The <b>logging.path</b> and <b>logging.file </b>properties can help with that:</p>
<pre class="highlight">logging:
 path: /opt/logs/
 file: MyApp.log
 level:
 root: WARN
 org:
 springframework:
 security: DEBUG
</pre>
<p>By default, the log files will rotate once they hit 10 megabytes in size.</p>
<p><b>application.properties:</b></p>
<pre class="highlight">logging.path=/opt/logs/
logging.file=MyApp.log
logging.level.root=WARN
logging.level.root.org.springframework.>You can also change name of logger configuration file name i.e. you can change name of file <b>logback.xml </b>to <b>log-config.xml</b> by setting the property<b> logging.config</b> in property file or <b>YML </b>file.<br />
<pre class="highlight">logging:
 config:
 classpath:log-config.xml
</pre>
<p>
<b>4. CONFIGURING A DATA SOURCE</b><br />
<b>application.yml:</b> if you’re using a MySQL database, your<b> application.yml</b> file might look like this</p>
<pre class="highlight">spring:
 datasource:
 url: jdbc:mysql://localhost/dojdb
 username: root
 password: root
</pre>
<p>
Specify driver name for database with property <b>spring.datasource</b><br />
<b>.driver-class-name</b> property as follows</p>
<pre class="highlight">spring:
 datasource:
 url: jdbc:mysql://localhost/dojdb
 username: root
 password: root
 driver-class-name: com.mysql.jdbc.Driver
</pre>
<p><b>Using JNDI for DataSource:</b><br />
By using property<b> spring.datasource.jndi-name</b></p>
<pre class="highlight">spring:
 datasource:
 jndi-name: java:/comp/env/jdbc/dojDBDS

</pre>
<p>
<b>Type-safe Configuration Properties</b><br />
If you are working with multiple properties or your data is hierarchical in nature then sometimes it may be problem in configuration properties. Spring Boot provides an alternative method of working with properties that allows strongly typed beans to govern and validate the configuration of your application.</p>
<p><b>For example:</b></p>
<pre class="highlight">@Component
@ConfigurationProperties(prefix="database")
public class DatabaseSettings {

 private String dbname;

 private String dburl;

 // ... getters and setters

}
</pre>
<p>The<b> @EnableConfigurationProperties </b>annotation is automatically applied to your project so that any beans annotated with <b>@ConfigurationProperties</b> will be configured from the Environment properties. The <b>@ConfigurationProperties</b> annotation won’t work unless you’ve enabled it by adding <b>@EnableConfigurationProperties</b> in one of your Spring configuration classes. This style of configuration works particularly well with the <b>SpringApplication </b>external <b>YAML </b>configuration:<br />
<b>application.yml</b></p>
<pre class="highlight">database:
 dbname: dojdb
 dburl: jdbc:mysql//192.168.1.1:3309/dojdb

# additional configuration as required
</pre>
<p>To work with <b>@ConfigurationProperties </b>beans you can just inject them in the same way as any other bean.</p>
<pre class="highlight">@Service
public class UserService {
 @Autowired
 private DatabaseSettings connection;
 //...
 @PostConstruct
 public void openConnection() {
 Server server = new Server();
 this.connection.configure(server);
 }
}
</pre>
<p>It is also possible to shortcut the registration of<b> @ConfigurationProperties</b> bean definitions by simply listing the properties classes directly in the <b>@EnableConfigurationProperties</b> annotation:</p>
<pre class="highlight">@Configuration
@EnableConfigurationProperties(DatabaseSettings.class)
public class DBConfiguration {
}
</pre>
<p><b>Using @ConfigurationProperties for outside beans:</b><br />
We can use <b>@ConfigurationProperties</b> for beans which either outside from the application or not in your control. Let‘s see below</p>
<pre class="highlight">@ConfigurationProperties(prefix = "foo")
@Bean
public FooComponent fooComponent() {
 ...
}
</pre>
<p>Any property defined with the foo prefix will be mapped onto that <b>FooComponent </b>bean in a similar manner as the <b>DatabaseSettings </b>example above.</p>
<p><b>Note: Biding Property in Spring Boot </b><br />
It’s also worth noting that Spring Boot’s property resolver is clever enough to treat camel-cased properties as interchangeable with similarly named properties with hyphens or underscores. In other words, a property named <b>database.dbName</b> is equivalent to both <b>database.db_name</b> and <b>database.db-name</b>. And also <b>DATABASE_DB_NAME </b>as environment variable in OS. </p>
<p><b>@ConfigurationProperties Validation</b><br />
Spring Boot will attempt to validate external configuration, by default using JSR-303 (if it is on the classpath). You can simply add <b>JSR-303</b> <b>javax.validation </b>constraint annotations to your @ConfigurationProperties class:</p>
<pre class="highlight">@Component
@ConfigurationProperties(prefix="database")
public class DatabaseSettings {
 @NotNull
 private String dbName;
 @NotNull
 private String dbUrl;
 // ... getters and setters
}

</pre>
<p>
<b>Configuring with profiles</b><br />
When applications are deployed to different runtime environments, there are usually some configuration details that will differ. The details of a database connection, for instance, are likely different in a development environment than in a quality assurance environment, and different still in a production environment.</p>
<pre class="highlight">@Configuration
@Profile("production")
public class ProductionConfiguration {
 // ...
}
</pre>
<p>The <b>@Profile</b> annotation used here requires that the “<b>production</b>” profile be active at runtime for this configuration to be applied. If the “<b>production</b>” profile isn’t active, this configuration will be ignored and applied any default auto configuration.</p>
<p><b>Activate profiles:</b><br />
Profiles can be activated by setting the <b><i>spring.profiles.active</i></b> property using any of the means available for setting any other configuration property. For example, you could activate the “<b>production</b>” profile by running the application at the <b>command line </b>like this:</p>
<pre class="highlight">$ java -jar MyApp-0.0.1-SNAPSHOT.jar -- spring.profiles.active=production
</pre>
<p>Or you can add the <i><b>spring.profiles.active</b></i> property to<b> application.yml:</b></p>
<pre class="highlight">spring:
 profiles:
 active: production
</pre>
<p><b>Profile-specific properties:</b><br />
If you’re using <b>application.properties</b> to express configuration properties, you can provide profile-specific properties by creating additional properties files named with the pattern “<b><i>application-{profile}.properties</i></b>”. Profile-specific properties are loaded from the same locations as standard <b><i>application.properties</i></b>, with profile-specific files always overriding the non-specific ones irrespective of whether the profile-specific files are inside or outside your packaged jar.</p>
<p><b>For Example</b> the <b>development configuration</b> would be in a file named <b>application-development.properties</b> and contain properties for verbose, console written logging:</p>
<pre class="highlight">logging.level.root=DEBUG
</pre>
<p>But for <b>production</b>, <b>application-production.properties</b> would configure logging to be at WARN level and higher and to write to a log file:</p>
<pre class="highlight">logging.path=/opt/logs/
logging.file=MyApp.log
logging.level.root=WARN
</pre>
<p><b>Multi-profile YAML documents:</b><br />
You can specify multiple profile-specific YAML documents in a single file by using a <b><i>spring.profiles</i></b> key to indicate when the document applies. For example:</p>
<pre class="highlight">logging:
 level:
 root: INFO
---
spring:
 profiles: development
logging:
 level:
 root: DEBUG
---
spring:
 profiles: production
logging:
 path: /opt/
 file: MyApp.log
 level:
 root: WARN
</pre>
<p>As you can see, this <b>application.yml</b> file is divided into three sections by a set of triple hyphens (---). The second and third sections each specify a value for <i><b>spring .profiles</b></i>. This property indicates which profile each section’s properties apply to.</p>
<p>The properties defined in the middle section apply to development because it sets <b><i>spring.profiles</i></b> to “<b>development</b>”. Similarly, the last section has <b><i>spring.profiles</i></b> set to “<b>production</b>”, making it applicable when the “<b>production</b>” profile is active.</p>
<p>The first section, on the other hand, doesn’t specify a value for <i><b>spring.profiles</b></i>. Therefore, its properties are common to all profiles or are defaults if the active profile doesn’t otherwise have the properties set.</p>
<p><b>Customizing error pages</b><br />
Spring Boot offers this “<b>whitelabel</b>” error page by default as part of auto-configuration. The default error handler that’s auto-configured by Spring Boot looks for a view whose name is “<b>error</b>”. The easiest way to customize the error page is to create a custom view that will resolve for a view named “<b>error</b>”.</p>
<p>Ultimately this depends on the view resolvers in place when the error view is being resolved. This includes</p>
<ul>
<li>Any bean that implements Spring’s View interface and has a bean ID of “<b>error</b>” (resolved by Spring’s BeanNameViewResolver)</li>
<li>A Thymeleaf template named “<b>error.html</b>” if Thymeleaf is configured</li>
<li>A FreeMarker template named “<b>error.ftl</b>” if FreeMarker is configured</li>
<li>A Velocity template named “<b>error.vm</b>” if Velocity is configured</li>
<li>A JSP template named “<b>error.jsp</b>” if using JSP views</li>
</ul>
<p>
<b>Summary</b><br />
Spring Boot Auto configuration do almost configuration for your application. When autoconfiguration doesn’t fit your needs, Spring Boot allows you to override and fine-tune the configuration it provides.</p>
<p>
Happy Spring Boot Learning!!!</p>
<div style="background-color: #f2f9fc; border-radius: 3px; border: 1px solid #c9e6f2; line-height: 1.45; padding: 16px;"><b>Spring Boot Related Topics</b></p>
<ol style="text-align: left;">
<li><b><a href="https://dineshonjava.com/2017/04/spring-boot-interview-questions-and-answers.html">Spring Boot Interview Questions and Answers</a></b></li>
<li><b><a href="https://dineshonjava.com/2016/06/introduction-to-spring-boot-a-spring-boot-complete-guide.html">Introduction to Spring Boot</a></b></li>
<li><a href="https://dineshonjava.com/2016/06/essentials-key-components-and-internals-of-spring-boot-framework.html"><b>Essentials and Key Components of Spring Boot</b></a></li>
<li><a href="https://dineshonjava.com/2016/06/spring-boot-cli-installation-and-hello-world-example.html"><b>Spring Boot CLI Installation and Hello World Example</b></a></li>
<li><a href="https://dineshonjava.com/2016/06/spring-boot-initilizr-web-interface-and-examples.html"><b>Spring Boot Initializr Web Interface</b></a></li>
<li><a href="https://dineshonjava.com/2016/06/spring-boot-initilizr-with-ides-via-spring-tool-suite.html"><b>Spring Boot Initializr With IDEs</b></a></li>
<li><a href="https://dineshonjava.com/2016/07/spring-boot-initializr-with-spring-boot-cli.html"><b>Spring Boot Initializr With Spring Boot CLI</b></a></li>
<li><a href="https://dineshonjava.com/2016/07/installing-spring-boot.html"><b>Installing Spring Boot</b></a></li>
<li><a href="https://dineshonjava.com/2016/07/developing-your-first-spring-boot-application-hello-world.html"><b>Developing your first Spring Boot application</b></a></li>
<li><a href="https://dineshonjava.com/2016/07/logging-configuration-in-spring-boot.html"><b>Logging Configuration in Spring Boot</b></a></li>
<li><a href="https://dineshonjava.com/2016/07/spring-boot-with-spring-mvc-application.html"><b>Spring Boot and Spring MVC</b></a></li>
<li><a href="https://dineshonjava.com/2016/08/working-with-sql-databases-in-spring-boot-application.html"><b>Working with SQL Databases and Spring Boot</b></a></li>
<li><a href="https://dineshonjava.com/2016/08/mysql-configuration-with-spring-boot.html"><b>MySQL Configurations</b></a></li>
<li><a href="https://dineshonjava.com/2016/08/spring-data-jpa-using-in-spring-boot-application.html"><b>Spring Data JPA using Spring Boot Application</b></a></li>
<li><a href="https://dineshonjava.com/2016/08/spring-boot-with-nosql-technologies.html"><b>Spring Boot with NoSQL technologies</b></a></li>
<li><a href="https://dineshonjava.com/2016/08/spring-cache-tutorial.html"><b>Spring Cache Tutorial</b></a></li>
<li><a href="https://dineshonjava.com/2016/08/spring-security-tutorial-using-spring-boot.html"><b>Spring Security Tutorial with Spring Boot</b></a></li>
<li><a href="https://dineshonjava.com/2016/08/spring-boot-and-mongodb-in-rest-application.html"><b>Spring Boot and MongoDB in REST Application</b></a></li>
<li><b><a href="https://dineshonjava.com/2016/08/spring-boot-actuator-complete-guide.html">Complete Guide for Spring Boot Actuator</a></b></li>
<li><b><a href="https://dineshonjava.com/2017/01/microservices-with-spring-boot.html">Microservices with Spring Boot</a></b>
</li>
</ol>
</div>
<p>
</div>
</div>
</div>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/developing-your-first-spring-boot-application-hello-world/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/logging-configuration-in-spring-boot/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '139'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…