How can i configure the Spring Boot Starter Application to use mysql instead of h2?

How can i configure the Spring Boot Application to use mysql instead of h2? I added to pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

and to application.yaml i added

spring:
  datasource:
    url: jdbc:mysql://192.168.0.60:3306/camunda
    username: root
    password: s3cr3t

What else should i do?

Hi @mbrain ,
->So you need Dependency:-
1.mysql connector java
2.Data JPA
->You have to download script from here SQL Script
→ Configure your workbench by running Script
→ If any doubt go through this link SQL with Camunda

Hi and thank you. I already created the database, the question is how to configure the camunda spring starter application.

Hi @mbrain ,
Generally we work with Spring right same here also, We will create

  1. Repository class (JPA repository for CRUD operation)
  2. Service class ( Service task , getting value from process and setting in one Entity object, inserting using save() method )
  3. Entity (Creating table and defining getter setter with Needed Variable )
    Instead of H2 , now we will configure our SQL Properties in Application.properties
    you can go through my code Github Code
    Regards,
    Avinash

I have no application.properties file in my camunda spring boot starter project. Please if you can tell me how i can do it in my own project, i dont want to use yours.

yaml file you have right, that is enough @mbrain

But why are you talking about properties file? I want to use a plain camunda spring starter example project. I am very new to that.

See for properties we need one file if it is application.yaml then we have to follow Indentation like you have given , if we are creating application.properties then we give value:

spring.datasource.url=jdbc:mysql://localhost:3306/camunda
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=update
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
spring.jpa.show-sql=true

camunda.bpm.admin-user.id=demo
camunda.bpm.admin-user.password=demo
camunda.bpm.admin-user.firstName=Demo
camunda.bpm.admin-user.lastName=Demo
camunda.bpm.filter.create=All Tasks

Both work same @mbrain

Ok i see but sorry, can you answer my question? Why is it not working for me? What am i missing?

Go through my Github Link and drop here your code and BPMN in ZIP
Regards,
Avinash

But there is a lot more than just mysql.

→ the lombok dependency,
→ the spring-boot-starter-mail,
→ the camunda-connect-soap-http-client,
→ the spring-cloud-starter-config

and more.

Do i need all this stuff for a simple mysql configuration?

The camunda run bundle was way easier to configure, i just dropped the sql-connector.jar into a directory, uncomment the block in pom.xml and that was it.

@mbrain You can refer to this Postgres config example. You can switch it to MySQL.

1 Like

No i dont want your code i want an explaination how to configure my own code.

In order to have MySQL instead of H2, you need to do the following:
In your pom.xml, you need to add the following dependencies:

<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <scope>runtime</scope>
</dependency>

What are these? The first one is Spring Data JPA, which makes handling data access easier. For more details, you may look here: Spring Data JPA
The second one is the actual connector used to communicate with the database.

Now, having these is only half of what you have to do. If you want to actually use them, as was said before, you need to configure them, which from the code you provided seems to be fine as you have it (in the application.yaml file). As a side note to this, make sure the database actually exists on your MySQL server, because otherwise your application may fail on startup.

Another note that may be of use to you: I would recommend not deleting the H2 dependency from the pom.xml file, because that my still be used during testing and your application may fail without it.

2 Likes