Spring Boot entry Third day: Configure the logging system and the Druid database connection pool.

Source: Internet
Author: User

First, log management

1. Add the following to the Application.properties file:

logging.level.root=WARNlogging.level.org.springframework.web=debuglogging.file=/log/log/  My.loglogging.pattern.console=%d{yyyy-mm-dd HH:mm:ss} [%thread]%-5level%logger-%msg%  Nlogging.pattern.file=%d{yyyy-mm-dd HH:mm:ss} [%thread]%-5level%logger-%msg%n

Sets the level of log output and generates log files. A little more simple, the last two lines can also not.

2. Use the SLF4J log framework:

Private Static Final Logger Logger = Loggerfactory.getlogger (usercontroller.  Class);
Logger.warn ("You performed the UserList2 () method in the Usercontroller class. ");

Well, I can't write too much.

Second, the configuration druid

1. Add the druid dependency in the Pom.xml file:

        <dependency>            <groupId>com.alibaba</groupId>            <artifactid>druid</artifactid >            <version>1.0.26</version>        </dependency>

2. Add a configuration class and copy someone's code directly:

 PackageCom.yws710.springboot.demo1;ImportCom.alibaba.druid.support.http.StatViewServlet;ImportCom.alibaba.druid.support.http.WebStatFilter;ImportOrg.slf4j.Logger;Importorg.slf4j.LoggerFactory;ImportOrg.springframework.boot.web.servlet.FilterRegistrationBean;ImportOrg.springframework.boot.web.servlet.ServletRegistrationBean;ImportOrg.springframework.context.annotation.Bean;Importorg.springframework.context.annotation.Configuration;ImportJava.util.HashMap;ImportJava.util.Map; @Configuration Public classdruidconfiguration {Private Static FinalLogger Logger = Loggerfactory.getlogger (druidconfiguration.class); @Bean PublicServletregistrationbean Druidservlet () {Logger.info ("Init Druid Servlet Configuration"); Servletregistrationbean Servletregistrationbean=NewServletregistrationbean (); Servletregistrationbean.setservlet (NewStatviewservlet ()); Servletregistrationbean.addurlmappings ("/druid/*"); Map<string, string> initparameters =NewHashmap<string, string>(); Initparameters.put ("Loginusername", "admin");//User nameInitparameters.put ("Loginpassword", "admin");//PasswordInitparameters.put ("Resetenable", "false");//disable the "Reset All" feature on HTML pagesInitparameters.put ("Allow", "");//IP Whitelist (no configuration or null, all access is allowed)//initparameters.put ("Deny", "192.168.20.38");//IP blacklist (deny takes precedence over allow when there is a common)servletregistrationbean.setinitparameters (initparameters); returnServletregistrationbean; } @Bean PublicFilterregistrationbean Filterregistrationbean () {Filterregistrationbean Filterregistrationbean=NewFilterregistrationbean (); Filterregistrationbean.setfilter (NewWebstatfilter ()); Filterregistrationbean.addurlpatterns ("/*"); Filterregistrationbean.addinitparameter ("Exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"); returnFilterregistrationbean; }}

3. Start the project. Enter Http://localhost:8080/druid/in the browser address bar

Because the user name and password are configured above, you need to log in:

Login success after the page will not, used Druid nature know, used to hurriedly use Ah, such a good thing.

Spring Boot entry Third day: Configure the logging system and the Druid database connection pool.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.