在build.gradle中,我有:
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-web-services'
compile 'org.springframework.boot:spring-boot-starter-amqp'
compile("org.springframework.boot:spring-boot-starter-jdbc") {
exclude module: "spring-boot-starter-hikari"
}
compile group: 'org.apache.tomcat', name: 'tomcat-jdbc', version: '9.0.21'
我尝试在application.yml(位于tomcat /../ resource_directory中)中配置数据源
spring:
datasource:
jdbc-url: "jdbc:oracle:thin: ...."
username: "admin"
password: "admin"
driver-class-name: "oracle.jdbc.driver.OracleDriver"
type: "org.apache.tomcat.jdbc.pool.DataSource"
tomcat:
initialSize: 55
max-wait: 10000
max-active: 50
max-idle: 15
min-idle: 8
default-autoCommit: false
我在代码中使用@Autowired。但是,当我调试代码时,我会下一步:
log.info("dataSource: " + dataSource.toString());1
log.info("dataSourceClass: " + dataSource.getClass());2
dataSource: HikariDataSource (null) 1
dataSourceClass: class com.zaxxer.hikari.HikariDataSource 2
在日志文件中,我接下来看到了
Loaded 1 document from YAML resource // with correct path to file.
并更正加载的数据:
spring={datasource={jdbc-url=jdbc...., username=admin, password=admin, driver-class-name=oracle.jdbc.driver.OracleDriver,
type=org.apache.tomcat.jdbc.pool.DataSource, tomcat={initialSize=55, max-
wait=10000, max-active=50, max-idle=15, min-idle=8, default-
autoCommit=false}}}
当我将config放入application.propertes中的src / resources中时,我得到了正确的tomcat dataSource。
dataSource: org.apache.tomcat.jdbc.pool.DataSourc //1
dataSourceClass: class org.apache.tomcat.jdbc.pool.DataSource//2
我做错了什么??帮我解决这个困惑。