idea使用druid的jar包_学习IDEA配置 Druid 遇到的“坑”-----记录1

POM.XML文件配置如下

1 <?xml version="1.0" encoding="UTF-8"?>

2

3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

4 4.0.0

5

6 org.springframework.boot

7 spring-boot-starter-parent

8 2.2.2.RELEASE

9

10

11 com.gaole

12 study

13 0.0.1-SNAPSHOT

14 study

15 Study Spring Boot

16

17

18 1.8

19

20

21

22

23 org.springframework.boot

24 spring-boot-starter-data-jdbc

25

26

27 org.springframework.boot

28 spring-boot-starter-web

29

30

31

32

33 com.alibaba

34 druid

35 1.1.9

36

37

38 mysql

39 mysql-connector-java

40 6.0.6

41

42

43 org.springframework.boot

44 spring-boot-starter-test

45 test

46

47

48 org.junit.vintage

49 junit-vintage-engine

50

51

52

53

54

55

56

57

58 org.springframework.boot

59 spring-boot-maven-plugin

60

61

62

63

64

application.yml  配置如下

spring:

datasource:

type: com.alibaba.druid.pool.DruidDataSource

druid:

driver-class-name: com.mysql.cj.jdbc.Driver

url: jdbc:mysql://localhost:3306/wxmp?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=false

username: root

password:111111initialSize:5minIdle:5maxActive:20# 配置获取连接等待超时的时间

maxWait:60000# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒

timeBetweenEvictionRunsMillis:60000# 配置一个连接在池中最小生存的时间,单位是毫秒

minEvictableIdleTimeMillis:300000validationQuery: SELECT1FROM DUAL

testWhileIdle:truetestOnBorrow:falsetestOnReturn:false# 打开PSCache,并且指定每个连接上PSCache的大小

poolPreparedStatements:truemaxPoolPreparedStatementPerConnectionSize:20# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙

#filters: stat,wall,log4j

# 通过connectProperties属性来打开mergeSql功能;慢SQL记录

connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000# 合并多个DruidDataSource的监控数据

useGlobalDataSourceStat:true# web-stat-filter:

# enabled:falsemybatis:

# 指定全局配置文件位置

config-location: classpath:mybatis/mybatis-config.xml

# 指定sql映射文件位置

mapper-locations: classpath:mybatis/mapper/*.xml

# schema:

# - classpath:sql/department.sql

# - classpath:sql/employee.sql

server:

port: 8082

IDEA创建项目时,啥也没写,就一个主程序

packagecom.gaole.study;importorg.springframework.boot.SpringApplication;importorg.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplicationpublic classStudyApplication {public static voidmain(String[] args) {

SpringApplication.run(StudyApplication.class, args);

}

}

编译通过,但是启动报错如下

***************************

APPLICATION FAILED TO START

***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class

配置了半天还是搞不定,后来

https://blog.csdn.net/qq_40223688/article/details/88191732

主类中加入

@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})

并重新导入需要的类,重新编译,启动,竟然好了,还是对SpringBoot的原理弄不清;

先记录下来,以后看;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值