springboot項目如果想在配置文件裏用加密的密碼直接配置而沒有解密的一些配置,是支持度不太好的。需要自己實現DataSource的一些配置。使用密文的連接,網上一堆我就不闡述了。這裏說的用明文來連接。
spring.datasource.url=jdbc:jtds:sqlserver://xxxxx
spring.datasource.username=xx
spring.datasource.password=xxxx
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.druid.initial-size=5
spring.datasource.druid.max-active=30
spring.datasource.druid.min-idle=1
spring.datasource.druid.max-wait=10
spring.datasource.druid.validation-query=select 'x'
pom 文件依賴:
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.20</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<scope>runtime</scope>
</dependency>
如果你沒按照我的配置有可能你會遇到這個錯誤:java.sql.SQLException: The SQL statement must not be null or empty
解釋如下:
特別注意的是如果你引用的druid的版本在1.1.6以下,就不需要加開頭紅色的配置。如果引用1.1.7及以上就需要加紅色的配置。如果是在java類中配置,在DruidDataSource對象中加一個這個屬性就可以了,否則會報錯: