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.