0

I have the following bean definition.

@Bean
public DataSource hikariDataSource() {
    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setJdbcUrl(JDBC_URL);
    hikariConfig.setUsername(USERNAME);
    hikariConfig.setPassword(PASSWORD);
    return new HikariDataSource(hikariConfig);
}

When I get application context.

ApplicationContext ctx = new AnnotationConfigApplicationContext("org.example");

An exception is being thrown

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hikariDataSource' defined in org.example.config.Configuration: Failed to instantiate [javax.sql.DataSource]: Factory method 'hikariDataSource' threw exception with message: null

Is there any idea what can be the reason?

1 Answers1

0

Maybe some of the answers from this thread will help.

https://stackoverflow.com/a/33213802/3816621

Also please check if you get @Configuration annotation on class level.

user3816621
  • 134
  • 7
  • The annotation is present. Also I have debugged and exception is being thrown after HikariConfig hikariConfig = new HikariConfig(); line. So I'm able to reach this line. – Varuzhan Stepanyan Jan 02 '23 at 16:19
  • If you configure Hikari by the book it could be also a problem with conflicting dependencies. – user3816621 Jan 02 '23 at 16:42