1

I am new to spring boot and mysql. I am trying to create an REST API with mysql config in the application.yml file. My yml file is shown below.

  datasource:
    driverClassName: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/test
    username:
    password:
  jpa:
    hibernate.ddl-auto: update
    generate-ddl: true
    show-sql: true

The problem is that I don't want to put my password in the yaml file. I want to use a key file or a bearer token. I am not sure how I can start with this. Please help. Thanks in Advance :)

imar
  • 25
  • 1
  • 1
  • 5
  • You could give jasypt a try: https://stackoverflow.com/questions/56579295/using-encrypted-password-for-database-connection-in-spring-boot-application-thro – Turo Nov 30 '20 at 18:14

2 Answers2

2

you can use Jasypt here to encrypt the DB password. and you can put it with ENC() key:--

spring:
datasource:
    driverClassName: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/test
    username:ENC(<incrypted username>)   // if you want
    password:ENC(<encrypted password>)
  jpa:
    hibernate.ddl-auto: update
    generate-ddl: true
    show-sql: true

Jasypt POM dependency for spring-boot:--

<!-- https://mvnrepository.com/artifact/com.github.ulisesbocchio/jasypt-spring-boot-starter -->
<dependency>
    <groupId>com.github.ulisesbocchio</groupId>
    <artifactId>jasypt-spring-boot-starter</artifactId>
    <version>2.1.1</version>
</dependency>

 

(For projects not using @SpringBootApplication or @EnableAutoConfiguration, then you can use the jasypt-spring-boot dependency directly) Others:--

<dependency>
    <groupId>com.github.ulisesbocchio</groupId>
    <artifactId>jasypt-spring-boot</artifactId>
    <version>2.0.0</version>
</dependency>

Wanna learn how encrypt/decrypt Jasypt key click: Jasypt

more deatail about Jasypt jasypt github

priyranjan
  • 674
  • 6
  • 15
0

The new driver class is - com.mysql.cj.jdbc.Driver

Serhii D
  • 56
  • 3