do i need to configure the beans in the example below for my spring data jdbc project?

If you include org.springframework.boot:spring-boot-starter-data-jdbc in dependencies in Maven or Gradle,By “Convention over configuration” paradigm, you shouldn’t need to create any bean at all include the dataSource bean. Just main method is enough. Those necessary beans will be created automatically.

@SpringBootApplication
public class SpringDataJdbcApplication
{
    public static void main(String[] args) 
    {
        SpringApplication.run(SpringDataJdbcApplication.class, args);
    }
    
}

and inside application.yml

...
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://dbhost/db
    username: xxx
    password: xxx
    max-active: 3
...

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top