资讯专栏INFORMATION COLUMN

SpringBoot进阶教程 | 第三篇:整合Druid连接池以及Druid监控

Ilikewhite / 855人阅读

摘要:这篇文篇将介绍,如何通过整合数据库链接池实时监控数据库链接信息,为优化数据库性能提供更好的指导,同样将通过配置文件形式进行配置方便简洁。

这篇文篇将介绍,如何通过SpringBoot整合Druid数据库链接池,实时监控数据库链接信息,为优化数据库性能提供更好的指导,同样将通过YML配置文件形式进行配置,方便简洁。

准备工作

环境:

</>复制代码

  1. windows
  2. jdk 8
  3. maven 3.0
  4. IDEA
创建数据库表

</>复制代码

  1. -- ----------------------------
  2. -- Table structure for student
  3. -- ----------------------------
  4. DROP TABLE IF EXISTS `student`;
  5. CREATE TABLE `student` (
  6. `sno` int(15) NOT NULL,
  7. `sname` varchar(50) DEFAULT NULL,
  8. `sex` char(2) DEFAULT NULL,
  9. `dept` varchar(25) DEFAULT NULL,
  10. `birth` date DEFAULT NULL,
  11. `age` int(3) DEFAULT NULL,
  12. PRIMARY KEY (`sno`)
  13. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  14. -- ----------------------------
  15. -- Records of student
  16. -- ----------------------------
  17. INSERT INTO `student` VALUES ("1", "李同学", "1", "王同学学习成绩很不错", "2010-07-22", "17");
构建工程

</>复制代码

  1. 4.0.0
  2. cn.zhangbox
  3. spring-boot-study
  4. 1.0-SNAPSHOT
  5. cn.zhangbox
  6. spring-boot-druid
  7. 0.0.1-SNAPSHOT
  8. jar
  9. spring-boot-druid
  10. this project for Spring Boot
  11. UTF-8
  12. UTF-8
  13. 1.8
  14. 3.4
  15. 1.10
  16. 1.2.0
  17. 1.16.14
  18. 1.2.41
  19. 1.1.2
  20. aliyunmaven
  21. http://maven.aliyun.com/nexus/content/groups/public/
  22. org.mybatis.spring.boot
  23. mybatis-spring-boot-starter
  24. ${mybatis-spring-boot.version}
  25. org.springframework.boot
  26. spring-boot-starter-web
  27. mysql
  28. mysql-connector-java
  29. runtime
  30. org.springframework.boot
  31. spring-boot-starter-test
  32. test
  33. org.apache.commons
  34. commons-lang3
  35. ${commons-lang3.version}
  36. commons-codec
  37. commons-codec
  38. ${commons-codec.version}
  39. com.alibaba
  40. fastjson
  41. ${fastjson.version}
  42. com.alibaba
  43. druid-spring-boot-starter
  44. ${druid.version}
  45. org.projectlombok
  46. lombok
  47. ${lombok.version}
  48. spring-boot-druid
  49. org.apache.maven.plugins
  50. maven-compiler-plugin
  51. 3.5.1
  52. 1.8
  53. 1.8
  54. UTF-8
  55. org.apache.maven.plugins
  56. maven-surefire-plugin
  57. 2.19.1
  58. org.springframework.boot
  59. spring-boot-maven-plugin
  60. org.springframework
  61. springloaded
  62. 1.2.4.RELEASE
  63. cn.zhangbox.admin.SpringBootDruidApplication
  64. -Dfile.encoding=UTF-8 -Xdebug
  65. -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005
  66. true
  67. true
  68. org.springframework.boot
  69. spring-boot-maven-plugin
  70. cn.zhangbox.admin.SpringBootDruidApplication
  71. -Dfile.encoding=UTF-8 -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005
  72. true
  73. true

注意:这里引入了lombok插件节省编写实体类时候写getset方法,这里在idea中进行setget操作需要下载lombok插件,在设置页面的plugins中搜索lombok插件在中央插件库下载后重启idea即可,更详细的lombok使用教程可以查考:

程序员DD的lombok系列教程:

Lombok:让JAVA代码更优雅

修改YML配置

</>复制代码

  1. #公共配置
  2. server:
  3. port: 80
  4. tomcat:
  5. uri-encoding: UTF-8
  6. spring:
  7. #激活哪一个环境的配置文件
  8. profiles:
  9. active: dev
  10. #连接池配置
  11. datasource:
  12. driver-class-name: com.mysql.jdbc.Driver
  13. # 使用druid数据源
  14. type: com.alibaba.druid.pool.DruidDataSource
  15. druid:
  16. # 配置测试查询语句
  17. validationQuery: SELECT 1 FROM DUAL
  18. # 初始化大小,最小,最大
  19. initialSize: 10
  20. minIdle: 10
  21. maxActive: 200
  22. # 配置一个连接在池中最小生存的时间,单位是毫秒
  23. minEvictableIdleTimeMillis: 180000
  24. testOnBorrow: false
  25. testWhileIdle: true
  26. removeAbandoned: true
  27. removeAbandonedTimeout: 1800
  28. logAbandoned: true
  29. # 打开PSCache,并且指定每个连接上PSCache的大小
  30. poolPreparedStatements: true
  31. maxOpenPreparedStatements: 100
  32. # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,"wall"用于防火墙
  33. filters: stat,wall,log4j
  34. # 通过connectProperties属性来打开mergeSql功能;慢SQL记录
  35. connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
  36. #mybatis
  37. mybatis:
  38. # 实体类扫描
  39. type-aliases-package: cn.zhangbox.springboot.entity
  40. # 配置映射文件位置
  41. mapper-locations: classpath:mapper/*.xml
  42. # 开启驼峰匹配
  43. mapUnderscoreToCamelCase: true
  44. ---
  45. #开发环境配置
  46. server:
  47. #端口
  48. port: 8080
  49. spring:
  50. profiles: dev
  51. # 数据源配置
  52. datasource:
  53. url: jdbc:mysql://127.0.0.1:3306/student?useUnicode=true&characterEncoding=utf8&useSSL=false&tinyInt1isBit=true
  54. username: root
  55. password: 123456
  56. #日志
  57. logging:
  58. config: classpath:log/logback.xml
  59. path: log/spring-boot-druid
  60. ---
  61. #测试环境配置
  62. server:
  63. #端口
  64. port: 80
  65. spring:
  66. profiles: test
  67. # 数据源配置
  68. datasource:
  69. url: jdbc:mysql://127.0.0.1:3306/spring-boot-druid?useUnicode=true&characterEncoding=utf8&useSSL=false&tinyInt1isBit=true
  70. username: root
  71. password: 123456
  72. #日志
  73. logging:
  74. config: classpath:log/logback.xml
  75. path: /home/log/spring-boot-druid
  76. ---
  77. #生产环境配置
  78. server:
  79. #端口
  80. port: 8080
  81. spring:
  82. profiles: prod
  83. # 数据源配置
  84. datasource:
  85. url: jdbc:mysql://127.0.0.1:3306/spring-boot-druid?useUnicode=true&characterEncoding=utf8&useSSL=false&tinyInt1isBit=true
  86. username: root
  87. password: 123456
  88. #日志
  89. logging:
  90. config: classpath:log/logback.xml
  91. path: /home/log/spring-boot-druid

这里进行了mybatis整合,如果不会mybatis整合可以参考我写的这篇文章:
SpringBoot非官方教程 | 第六篇:SpringBoot整合mybatis

创建日志配置文件

在工程resources文件夹下新建文件夹log,并在该文件夹下创建logback.xml文件,加入以下配置:

</>复制代码

  1. ${CONSOLE_LOG_PATTERN}
  2. UTF-8
  3. info
  4. ${LOG_PATH}/log_debug.log
  5. %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
  6. UTF-8
  7. ${LOG_PATH}/debug/log-debug-%d{yyyy-MM-dd}.%i.log
  8. 500MB
  9. 30
  10. debug
  11. ACCEPT
  12. DENY
  13. ${LOG_PATH}/log_info.log
  14. %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
  15. UTF-8
  16. ${LOG_PATH}/info/log-info-%d{yyyy-MM-dd}.%i.log
  17. 500MB
  18. 30
  19. info
  20. ACCEPT
  21. DENY
  22. ${LOG_PATH}/log_warn.log
  23. %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
  24. UTF-8
  25. ${LOG_PATH}/warn/log-warn-%d{yyyy-MM-dd}.%i.log
  26. 500MB
  27. 30
  28. warn
  29. ACCEPT
  30. DENY
  31. ${LOG_PATH}/log_error.log
  32. %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
  33. UTF-8
  34. ${LOG_PATH}/error/log-error-%d{yyyy-MM-dd}.%i.log
  35. 500MB
  36. 30
  37. error
  38. ACCEPT
  39. DENY

注意:loback配置文件中

</>复制代码

name的属性值一定要是当前工程的java代码的完整目录,因为mybatis打印的日志级别是debug级别的,因此需要配置debug级别日志扫描的目录。

创建Druid配置类

在工程java代码目录下创建config的目录在下面创建DruidDBConfig类加入以下代码:

</>复制代码

  1. @Configuration
  2. public class DruidDBConfig {
  3. @Bean
  4. public ServletRegistrationBean druidServlet() {
  5. ServletRegistrationBean reg = new ServletRegistrationBean();
  6. reg.setServlet(new StatViewServlet());
  7. reg.addUrlMappings("/druid/*");
  8. //设置控制台管理用户
  9. reg.addInitParameter("loginUsername","root");
  10. reg.addInitParameter("loginPassword","root");
  11. // 禁用HTML页面上的“Reset All”功能
  12. reg.addInitParameter("resetEnable","false");
  13. //reg.addInitParameter("allow", "127.0.0.1"); //白名单
  14. return reg;
  15. }
  16. @Bean
  17. public FilterRegistrationBean filterRegistrationBean() {
  18. //创建过滤器
  19. FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
  20. filterRegistrationBean.setFilter(new WebStatFilter());
  21. Map initParams = new HashMap();
  22. //忽略过滤的形式
  23. initParams.put("exclusions", "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*");
  24. filterRegistrationBean.setInitParameters(initParams);
  25. //设置过滤器过滤路径
  26. filterRegistrationBean.addUrlPatterns("/*");
  27. return filterRegistrationBean;
  28. }
  29. }

注意:这里ServletRegistrationBean 配置bean中通过addInitParameter设置了管控台的用户名密码都是root,可以在这里进行自定义配置也可以将这里的用户名密码通过转移数据库进行定制化配置实现。

创建实体

在工程java代码目录下创建entity的目录在下面创建Student类加入以下代码:

</>复制代码

  1. @Data
  2. @EqualsAndHashCode(callSuper = false)
  3. public class Student {
  4. private static final long serialVersionUID = 1L;
  5. /**
  6. * 主键id
  7. */
  8. private Integer sno;
  9. /**
  10. * 学生姓名
  11. */
  12. private String sname;
  13. /**
  14. * 性别
  15. */
  16. private String sex;
  17. /**
  18. * 生日
  19. */
  20. private String birth;
  21. /**
  22. * 年龄
  23. */
  24. private String age;
  25. /**
  26. * 简介
  27. */
  28. private String dept;
  29. }
创建Controller

在工程java代码目录下创建controller的目录在下面创建StudentConteroller类加入以下代码:

</>复制代码

  1. @Controller
  2. @RequestMapping("/student")
  3. public class StudentConteroller {
  4. private static final Logger LOGGER = LoggerFactory.getLogger(StudentConteroller.class);
  5. @Autowired
  6. protected StudentService studentService;
  7. /**
  8. * 查询所有的学生信息
  9. *
  10. * @param sname
  11. * @param age
  12. * @param modelMap
  13. * @return
  14. */
  15. @ResponseBody
  16. @GetMapping("/list")
  17. public String list(String sname, Integer age, ModelMap modelMap) {
  18. String json = null;
  19. try {
  20. List studentList = studentService.getStudentList(sname, age);
  21. modelMap.put("ren_code", "0");
  22. modelMap.put("ren_msg", "查询成功");
  23. modelMap.put("studentList", studentList);
  24. json = JSON.toJSONString(modelMap);
  25. } catch (Exception e) {
  26. e.printStackTrace();
  27. modelMap.put("ren_code", "0");
  28. modelMap.put("ren_msg", "查询失败===>" + e);
  29. LOGGER.error("查询失败===>" + e);
  30. json = JSON.toJSONString(modelMap);
  31. }
  32. return json;
  33. }
  34. }
创建Service

在工程java代码目录下面创建service目录在下面创建StudentService类加入以下代码:

</>复制代码

  1. public interface StudentService {
  2. /**
  3. * 查询所有的学生信息
  4. *
  5. * @param sname
  6. * @param age
  7. * @return
  8. */
  9. List getStudentList(String sname, Integer age);
  10. }
创建ServiceImpl

在工程java代码目录下的service的目录下面创建impl目录在下面创建StudentServiceImpl类加入以下代码:

</>复制代码

  1. @Service("StudentService")
  2. @Transactional(readOnly = true, rollbackFor = Exception.class)
  3. public class StudentServiceImpl implements StudentService {
  4. @Autowired
  5. StudentDao studentDao;
  6. @Override
  7. public List getStudentList(String sname, Integer age) {
  8. return studentDao.getStudentList(sname,age);
  9. }
  10. }
创建Dao

在工程java代码目录下创建dao的目录在下面创建StudentDao类加入以下代码:

</>复制代码

  1. public interface StudentDao {
  2. List getStudentList(@Param("sname")String sname, @Param("age")Integer age);
  3. }
创建Mapper映射文件

在工程resource目录下创建mapper的目录在下面创建StudentMapper.xml映射文件加入以下代码:

</>复制代码

创建启动类

</>复制代码

  1. @SpringBootApplication
  2. @MapperScan("cn.zhangbox.springboot.dao")//配置mybatis接口包扫描
  3. public class SpringBootDruidApplication extends SpringBootServletInitializer {
  4. public static void main(String[] args) {
  5. SpringApplication.run(SpringBootDruidApplication.class, args);
  6. }
  7. }
启动项目进行测试: 控制台打印

</>复制代码

  1. . ____ _ __ _ _
  2. / / ___"_ __ _ _(_)_ __ __ _
  3. ( ( )\___ | "_ | "_| | "_ / _` |
  4. / ___)| |_)| | | | | || (_| | ) ) ) )
  5. " |____| .__|_| |_|_| |_\__, | / / / /
  6. =========|_|==============|___/=/_/_/_/
  7. :: Spring Boot :: (v1.5.3.RELEASE)
  8. 2018-07-07 10:54:52.404 INFO 24084 --- [ main] c.z.s.SpringBootDruidApplication : Starting SpringBootDruidApplication on HP with PID 24084 (C:UsersAdministratorDesktopspring-boot-studyspring-boot-druid
  9. argetclasses started by Administrator in C:UsersAdministratorDesktopspring-boot-study)
  10. 2018-07-07 10:54:52.445 INFO 24084 --- [ main] c.z.s.SpringBootDruidApplication : The following profiles are active: dev
  11. 2018-07-07 10:54:52.570 INFO 24084 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@53142455: startup date [Sat Jul 07 10:54:52 CST 2018]; root of context hierarchy
  12. 2018-07-07 10:54:52.997 INFO 24084 --- [kground-preinit] o.h.validator.internal.util.Version : HV000001: Hibernate Validator 5.3.5.Final
  13. 2018-07-07 10:54:53.736 INFO 24084 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean "filterRegistrationBean" with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=druidDBConfig; factoryMethodName=filterRegistrationBean; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [cn/zhangbox/springboot/config/DruidDBConfig.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=com.alibaba.druid.spring.boot.autoconfigure.stat.DruidWebStatFilterConfiguration; factoryMethodName=filterRegistrationBean; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/alibaba/druid/spring/boot/autoconfigure/stat/DruidWebStatFilterConfiguration.class]]
  14. 2018-07-07 10:54:54.887 INFO 24084 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
  15. 2018-07-07 10:54:54.903 INFO 24084 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
  16. 2018-07-07 10:54:54.905 INFO 24084 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.14
  17. 2018-07-07 10:54:55.123 INFO 24084 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
  18. 2018-07-07 10:54:55.124 INFO 24084 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2554 ms
  19. 2018-07-07 10:54:55.522 INFO 24084 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: "statViewServlet" to [/druid/*]
  20. 2018-07-07 10:54:55.525 INFO 24084 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: "dispatcherServlet" to [/]
  21. 2018-07-07 10:54:55.525 INFO 24084 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: "statViewServlet" to [/druid/*]
  22. 2018-07-07 10:54:55.526 INFO 24084 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet statViewServlet was not registered (possibly already registered?)
  23. 2018-07-07 10:54:55.531 INFO 24084 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: "characterEncodingFilter" to: [/*]
  24. 2018-07-07 10:54:55.531 INFO 24084 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: "hiddenHttpMethodFilter" to: [/*]
  25. 2018-07-07 10:54:55.532 INFO 24084 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: "httpPutFormContentFilter" to: [/*]
  26. 2018-07-07 10:54:55.533 INFO 24084 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: "requestContextFilter" to: [/*]
  27. 2018-07-07 10:54:55.533 INFO 24084 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: "webStatFilter" to urls: [/*]
  28. 2018-07-07 10:54:57.216 INFO 24084 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@53142455: startup date [Sat Jul 07 10:54:52 CST 2018]; root of context hierarchy
  29. 2018-07-07 10:54:57.322 INFO 24084 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/student/list],methods=[GET]}" onto public java.lang.String cn.zhangbox.springboot.controller.StudentConteroller.list(java.lang.String,java.lang.Integer,org.springframework.ui.ModelMap)
  30. 2018-07-07 10:54:57.326 INFO 24084 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
  31. 2018-07-07 10:54:57.328 INFO 24084 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
  32. 2018-07-07 10:54:57.376 INFO 24084 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
  33. 2018-07-07 10:54:57.376 INFO 24084 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
  34. 2018-07-07 10:54:57.451 INFO 24084 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
  35. 2018-07-07 10:54:58.066 INFO 24084 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
  36. 2018-07-07 10:54:58.068 INFO 24084 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name "statFilter" has been autodetected for JMX exposure
  37. 2018-07-07 10:54:58.069 INFO 24084 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name "dataSource" has been autodetected for JMX exposure
  38. 2018-07-07 10:54:58.077 INFO 24084 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located MBean "dataSource": registering with JMX server as MBean [com.alibaba.druid.spring.boot.autoconfigure:name=dataSource,type=DruidDataSourceWrapper]
  39. 2018-07-07 10:54:58.081 INFO 24084 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located MBean "statFilter": registering with JMX server as MBean [com.alibaba.druid.filter.stat:name=statFilter,type=StatFilter]
  40. 2018-07-07 10:54:58.101 INFO 24084 --- [ main] o.a.coyote.http11.Http11NioProtocol : Initializing ProtocolHandler ["http-nio-8080"]
  41. 2018-07-07 10:54:58.118 INFO 24084 --- [ main] o.a.coyote.http11.Http11NioProtocol : Starting ProtocolHandler ["http-nio-8080"]
  42. 2018-07-07 10:54:58.145 INFO 24084 --- [ main] o.a.tomcat.util.net.NioSelectorPool : Using a shared selector for servlet write/read
  43. 2018-07-07 10:54:58.172 INFO 24084 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
  44. 2018-07-07 10:54:58.179 INFO 24084 --- [ main] c.z.s.SpringBootDruidApplication : Started SpringBootDruidApplication in 7.666 seconds (JVM running for 10.386)
  45. 2018-07-07 11:00:00.245 INFO 24084 --- [nio-8080-exec-5] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet "dispatcherServlet"
  46. 2018-07-07 11:00:00.246 INFO 24084 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet : FrameworkServlet "dispatcherServlet": initialization started
  47. 2018-07-07 11:00:00.302 INFO 24084 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet : FrameworkServlet "dispatcherServlet": initialization completed in 56 ms
  48. 2018-07-07 11:00:01.606 INFO 24084 --- [nio-8080-exec-5] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} inited
浏览器请求测试

本地日志打印效果


</>复制代码

  1. 2018-07-07 10:54:52.439 [main] DEBUG cn.zhangbox.springboot.SpringBootDruidApplication - Running with Spring Boot v1.5.3.RELEASE, Spring v4.3.8.RELEASE
  2. 2018-07-07 11:00:01.715 [http-nio-8080-exec-5] DEBUG c.z.springboot.dao.StudentDao.getStudentList - ==> Preparing: SELECT s.sno, s.sname, s.sex, s.dept, s.birth, s.age FROM student s WHERE 1 = 1
  3. 2018-07-07 11:00:01.881 [http-nio-8080-exec-5] DEBUG c.z.springboot.dao.StudentDao.getStudentList - ==> Parameters:
  4. 2018-07-07 11:00:01.931 [http-nio-8080-exec-5] DEBUG c.z.springboot.dao.StudentDao.getStudentList - <== Total: 2

这里使用logback配置中将不同级别的日志设置了在不同文件中打印,这样很大程度上方便项目出问题查找问题。

Druid管控台




源码地址

Spring Boot整合Druid连接池以及Druid监控源码

欢迎关注我的微信公众号获取更多更全的学习资源,视频资料,技术干货!

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/71506.html

相关文章

  • SpringCloud核心教程 | 三篇:服务注册与发现 Eureka篇

    摘要:下一篇介绍基于的服务注册与调用。服务提供者工程配置这里服务提供者是使用之前进阶教程第三篇整合连接池以及监控改造而来,这里一样的部分就不再重复说明,下面将说明新增的部分。 Spring Cloud简介 Spring Cloud是一个基于Spring Boot实现的云应用开发工具,它为基于JVM的云应用开发中涉及的配置管理、服务发现、断路器、智能路由、微代理、控制总线、全局锁、决策竞选、分...

    scq000 评论0 收藏0
  • Java3y文章目录导航

    摘要:前言由于写的文章已经是有点多了,为了自己和大家的检索方便,于是我就做了这么一个博客导航。 前言 由于写的文章已经是有点多了,为了自己和大家的检索方便,于是我就做了这么一个博客导航。 由于更新比较频繁,因此隔一段时间才会更新目录导航哦~想要获取最新原创的技术文章欢迎关注我的公众号:Java3y Java3y文章目录导航 Java基础 泛型就这么简单 注解就这么简单 Druid数据库连接池...

    KevinYan 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<