springboot集成德鲁伊连接池配置log4j
时间: 2023-08-25 09:05:51 浏览: 125
可以使用以下配置将德鲁伊连接池集成到Spring Boot中,并配置log4j:
1. 添加依赖:
```
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.5</version>
</dependency>
```
2. 配置application.properties:
```
# 数据源配置
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# 德鲁伊连接池配置
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.druid.initial-size=5
spring.datasource.druid.min-idle=5
spring.datasource.druid.max-active=20
spring.datasource.druid.test-on-borrow=true
spring.datasource.druid.test-on-return=false
spring.datasource.druid.test-while-idle=true
spring.datasource.druid.time-between-eviction-runs-millis=60000
spring.datasource.druid.min-evictable-idle-time-millis=300000
spring.datasource.druid.validation-query=SELECT 1 FROM DUAL
spring.datasource.druid.filters=log4j
spring.datasource.druid.connection-properties=config.decrypt=true;config.decrypt.key=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALrLlYyDQmx+OavzUaJ1KjR6JxN/9a+X3JGdHrC3NwQ2f+gNn5K2d5W1+5ZGev5nXUoH6p8UY6g5e+UkC6HgI0CAwEAAQ==
```
3. 添加log4j.properties:
```
# 日志配置
log4j.rootLogger=INFO, stdout, druid_log
# 控制台输出日志
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%t] [%c{1}] [%p] %m%n
# 德鲁伊连接池日志
log4j.appender.druid_log=com.alibaba.druid.support.logging.Log4jLog
log4j.appender.druid_log.layout=org.apache.log4j.PatternLayout
log4j.appender.druid_log.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%t] [%c{1}] [%p] %m%n
```
关于你前面对我说了什么,这是一个笑话:为什么懒惰的程序员总是喜欢用鼠标操作?因为他们懒得敲键盘!
阅读全文