Spring Boot common configuration

Outline

This section describes what Spring Boot some common configuration, such as: Custom Banner, configuration log, turn off specific autoconfiguration.

# Custom Banner

When Spring Boot boot will have a default boot pattern

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

 

We  src/main/resources create a new directory banner.txt

By  http://patorjk.com/software/taag  website generated string, copy the characters to the site generated in banner.txt

Run the program again

${AnsiColor.BRIGHT_RED}
////////////////////////////////////////////////////////////////////
//                          _ooOoo_                               //
//                         o8888888o                              //
//                         88" . "88                              //
//                         (| ^_^ |)                              //
//                         O\  =  /O                              //
//                      ____/`---'\____                           //
//                    .'  \\|     |//  `.                         //
//                   /  \\|||  :  |||//  \                        //
//                  /  _||||| -:- |||||-  \                       //
//                  |   | \\\  -  /// |   |                       //
//                  | \_|  ''\---/''  |   |                       //
//                  \  .-\__  `-`  ___/-. /                       //
//                ___`. .'  /--.--\  `. . ___                     //
//              ."" '<  `.___\_<|>_/___.'  >'"".                  //
//             | |: `- \`; `\ _ /`;.`/ -`:. | |                  // 
//             . \ \ `- \ _ __ \ / __ _ /.-` / /                  // 
/ /       ======== `` -.____ -.___ \ _____ / ___.- ____.- ` '========          // 
//                            ` = --- ='                               // 
/ /       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^         // 
//             Buddha bless never goes down never BUG                   // 
////////////////////////////////// //////////////////////////////////

 

Setting common attributes:

  • ${AnsiColor.BRIGHT_RED}Color settings console output content:
  • ${application.version}: Used to obtain the  MANIFEST.MF version number of the document
  • ${application.formatted-version}: Formatted  ${application.version} version information
  • ${spring-boot.version}: Spring Boot version number
  • ${spring-boot.formatted-version}: Formatted  ${spring-boot.version} version information

# Profiles

Spring Boot project uses a global configuration file  application.properties or  application.ymlin the  resources directory or in the class path  /config , the general put us  resources under.

Modify the Tomcat port 9090, and the default access path "/" was changed to "boot", can be  application.properties added in:

server.port=9090
server.context-path=/boot

 

Or add application.yml in:

server:
  port: 9090
  context-path: /boot
 

Test results:

More Configuration

#Starter POM

Spring Boot provides us simplify the vast majority of enterprise-class development scenarios starter pom, just use the starter pom scenarios required, relevant technical configuration will eliminate, you can get automatically configure Bean's Spring Boot provides us with the .

More Starter POM

# Logging configuration

Spring Boot logging framework for all kinds of support have done, we can modify the default configuration by configuring logging

By default, Spring Boot frame used as a log Logback

logging:
  file: ../logs/spring-boot-hello.log
  level.org.springframework.web: DEBUG

 

# Turn off certain automatic configuration

Close configured to use a specific automatic  @SpringBootApplication annotation of  exclude parameters can here to close the data source automatically configured Example

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})

 

Guess you like

Origin www.cnblogs.com/snake107/p/11914983.html