开发者社区> 问答> 正文

springboot yml配置问题 - java报错

  在学习springboot用yml进行配置的时候有一个疑惑,例如:spring.datasource下的数据库最大等待时间,一些资料写的是max-wait,但是一些资料又写的是maxWait,个人觉得,从程序方面来说,这两个是完全不一样的字符串,所以不知道框架是对这两种写法都支持,还是其中一种写法其实是错误的(写法不对写了也不会生效)。如果都支持,最好能提供下大概是如何实现的

展开
收起
montos 2020-05-31 19:40:45 980 0
1 条回答
写回答
取消 提交回答
  • spring boot 2 官方文档,自己找下

     

    ```yml

    # DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
    spring.datasource.continue-on-error=false # Whether to stop if an error occurs while initializing the database.
    spring.datasource.data= # Data (DML) script resource references.
    spring.datasource.data-username= # Username of the database to execute DML scripts (if different).
    spring.datasource.data-password= # Password of the database to execute DML scripts (if different).
    spring.datasource.dbcp2.*= # Commons DBCP2 specific settings
    spring.datasource.driver-class-name= # Fully qualified name of the JDBC driver. Auto-detected based on the URL by default.
    spring.datasource.generate-unique-name=false # Whether to generate a random datasource name.
    spring.datasource.hikari.*= # Hikari specific settings
    spring.datasource.initialization-mode=embedded # Initialize the datasource with available DDL and DML scripts.
    spring.datasource.jmx-enabled=false # Whether to enable JMX support (if provided by the underlying pool).
    spring.datasource.jndi-name= # JNDI location of the datasource. Class, url, username & password are ignored when set.
    spring.datasource.name= # Name of the datasource. Default to "testdb" when using an embedded database.
    spring.datasource.password= # Login password of the database.
    spring.datasource.platform=all # Platform to use in the DDL or DML scripts (such as schema-${platform}.sql or data-${platform}.sql).
    spring.datasource.schema= # Schema (DDL) script resource references.
    spring.datasource.schema-username= # Username of the database to execute DDL scripts (if different).
    spring.datasource.schema-password= # Password of the database to execute DDL scripts (if different).
    spring.datasource.separator=; # Statement separator in SQL initialization scripts.
    spring.datasource.sql-script-encoding= # SQL scripts encoding.
    spring.datasource.tomcat.*= # Tomcat datasource specific settings
    spring.datasource.type= # Fully qualified name of the connection pool implementation to use. By default, it is auto-detected from the classpath.
    spring.datasource.url= # JDBC URL of the database.
    spring.datasource.username= # Login username of the database.
    spring.datasource.xa.data-source-class-name= # XA datasource fully qualified name.
    spring.datasource.xa.properties= # Properties to pass to the XA data source.

    ```

     

    ######

    不同类型的数据库连接池读取的配置参数名不同,springboot如果没有指定数据库连接池,默认使用tomcat-jdbc连接池,其连接池参数配置:

    spring.datasource.max-wait=10000
    ######我意思是,有些资料(yml写法)写的是spring:datasource:maxWait,有些又写的是spring:datasource:max-wait,所以到底哪个才是正确的配置写法######

    这跟版本有关系的大兄dei

    ######

    这个和yml文件没关系的,和spring boot中@ConfigurationProperties注解有关

    2020-05-31 19:40:55
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载