begin with the h2 and spring-boot-starter-data-jpa dependencies:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>

Database Configuration

By default, Spring Boot configures the application to connect to an in-memory store with the username sa and an empty password.

However, we can change those parameters by adding the following properties to the application.properties file:

Default password is empty but when you write any “password “ you just assign new passoword

spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

we can change the location of data store FILE-BASED instead of IN MEMORY

spring.datasource.url=jdbc:h2:file:/data/demo

Accessing the H2 Console

If we don’t enable it we can not access, we need to add…


Hello I will show you really fast how to use Swagger with spring boot app.

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>

After adding to pom.xml

@EnableSwagger2
@Configuration
public class SpringFoxConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.todo.controller"))
.paths(PathSelectors.any())
.build();
}
}

After open the browser with this link

http://localhost:8080/swagger-ui/index.html

Also you can check with url http://localhost:8080/v2/api-docs

Tayfun ÇELİK

Full Stack Developer Java & Angular https://www.linkedin.com/in/tayfuncelik/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store