Chinaunix首页 | 论坛 | 博客
  • 博客访问: 625651
  • 博文数量: 142
  • 博客积分: 116
  • 博客等级: 入伍新兵
  • 技术积分: 1445
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-28 08:37
文章分类

全部博文(142)

文章存档

2017年(7)

2016年(57)

2015年(48)

2014年(30)

我的朋友

分类: Java

2017-01-19 14:56:12

在springboot的application.properties中,配置各种数据库的方法:


mysql

  1. spring.jpa.database=MYSQL
  2. spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
  3. spring.datasource.driver-class-name=com.mysql.jdbc.Driver
  4. spring.datasource.url=jdbc:mysql://127.0.0.1:3306/mydbname?useSSL=false
  5. spring.datasource.username=user1
  6. spring.datasource.password=user1

  1. <dependency>
  2.     <groupId>mysql</groupId>
  3.     <artifactId>mysql-connector-java</artifactId>
  4.     <version>5.1.34</version>
  5. </dependency>




oracle


  1. spring.jpa.database = oracle
  2. spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.Oracle10gDialect
  3. spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver
  4. spring.datasource.url=jdbc:oracle:thin:@127.0.0.1:1521:xe
  5. spring.datasource.username=user1
  6. spring.datasource.password=user1


  1. <dependency>
  2.     <groupId>com.oracle</groupId>
  3.     <artifactId>ojdbc7</artifactId>
  4.     <version>12.1.0.2.0</version>
  5. </dependency>





sqlserver


  1. spring.jpa.database = sql_server
  2. spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.SQLServerDialect
  3. spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
  4. spring.datasource.url=jdbc:sqlserver://127.0.0.1:1433;databaseName=mydbname
  5. spring.datasource.username=user1
  6. spring.datasource.password=user1

  1. <dependency>
  2.     <groupId>com.microsoft.sqlserver</groupId>
  3.     <artifactId>mssql-jdbc</artifactId>
  4.     <version>6.1.0.jre8</version>
  5. </dependency>





连接池设置

  1. spring.datasource.max-active=20
  2. spring.datasource.max-idle=8
  3. spring.datasource.min-idle=8
  4. spring.datasource.initial-size=10

  5. spring.jpa.show-sql=true

  6. # Hibernate ddl auto (create, create-drop, update)
  7. spring.jpa.hibernate.ddl-auto=update

  8. # physical_naming_strategy 避免java属性映射到数据库字段时,驼峰转下划线
  9. spring.jpa.properties.hibernate.physical_naming_strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl


各种数据库对应的validationQuery

  1. # sqlserver
  2. spring.datasource.validationQuery=SELECT 1
  3. # oracle
  4. spring.datasource.validationQuery=SELECT 1 FROM DUAL
  5. # mysql
  6. spring.datasource.validationQuery=SELECT 1 FROM DUAL






阅读(14379) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~