其实只需要配置一个 : druidDataSource 这个就可以了。
FilterRegistrationBean 与 ServletRegistrationBean 主要是为了试一试 Druid的监控介面而已,不要的话,完全没有问题的。
2)配置文件
#datasource
spring:
datasource:
name: testdb
url: jdbc:mysql://localhost:3306/spring_boot?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
username: root
password: root
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
#initalSize: 5
filters: stat
applictaion.yaml文件里面把这些提供一下,OK,鸟德配置成功。
三 配置文件的读到,各种坑,慢慢踩
暂且说有两种配置文件吧,
第一种,application.yaml 这个,注意,springboot中 @Configraperporties 标记的 配置节点,读到的都是application.yaml或得application.properties 里面的值的。
第二种,自定义的配置文件,注意,虽然 springboot 号称能读取.YAML文件,但是,只限 application.yaml 这一个,自定义的文件,只能用 .properties的文件做后缀才能读的到。
@PropertySource(value = {"classpath:config/globalconfig.properties"}) 是不能读取 .yaml文件。
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-54897-2.html
其实我作为大陆人十分理解台胞和香港人的关切