Error creating bean with name datasourcescriptdatabaseinitializer

Error creating bean with name dataSourceScriptDatabaseInitializer defined in class path resource

Questions : Error creating bean with name dataSourceScriptDatabaseInitializer defined in class path resource

2022-09-16T05:05:26+00:00 2022-09-16T05:05:26+00:00

419

Hello everyone I'm facing issue with running anycodings_heroku-postgres heroku server locally I believe there's anycodings_heroku-postgres more then one error but I don't know what is anycodings_heroku-postgres the main issue. I have add procfile and the anycodings_heroku-postgres database configuration as provided bellow anycodings_heroku-postgres in the code.

6:43:37 PM web.1 |  ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
6:43:37 PM web.1 |   \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
6:43:37 PM web.1 |    '  |____| .__|_| |_|_| |_\__, | / / / /
6:43:37 PM web.1 |   :: Spring Boot ::                (v2.6.1)
6:43:37 PM web.1 |  2021-12-14 18:43:37.764  INFO 269 --- [           main] c.discount.discount.DiscountApplication  : Starting DiscountApplication using Java 11.0.11 on Sabbagh99 with PID 269 (/mnt/c/Users/ad199/IdeaProjects/Discounts-Web-Api-old/build/libs/discount-0.0.1-SNAPSHOT.jar started by sabbagh99 in /mnt/c/Users/ad199/IdeaProjects/Discounts-Web-Api-old)
6:43:37 PM web.1 |  2021-12-14 18:43:37.777  INFO 269 --- [           main] c.discount.discount.DiscountApplication  : No active profile set, falling back to default profiles: default
6:43:39 PM web.1 |  2021-12-14 18:43:39.864  INFO 269 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
6:43:40 PM web.1 |  2021-12-14 18:43:40.022  INFO 269 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 123 ms. Found 1 JPA repository interfaces.
6:43:41 PM web.1 |  2021-12-14 18:43:41.697  INFO 269 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
6:43:41 PM web.1 |  2021-12-14 18:43:41.727  INFO 269 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
6:43:41 PM web.1 |  2021-12-14 18:43:41.727  INFO 269 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.55]
6:43:41 PM web.1 |  2021-12-14 18:43:41.981  INFO 269 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
6:43:41 PM web.1 |  2021-12-14 18:43:41.981  INFO 269 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3820 ms
6:43:42 PM web.1 |  2021-12-14 18:43:42.202  WARN 269 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method 'dataSource
6:43:42 PM web.1 |  >  ScriptDatabaseInitializer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'databaseConfig': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.datasource.url' in value "${spring.datasource.url}"
6:43:42 PM web.1 |  2021-12-14 18:43:42.210  INFO 269 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
6:43:42 PM web.1 |  2021-12-14 18:43:42.262  INFO 269 --- [           main] ConditionEvaluationReportLoggingListener :
6:43:42 PM web.1 |  Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
6:43:42 PM web.1 |  2021-12-14 18:43:42.346 ERROR 269 --- [           main] o.s.boot.SpringApplication               : Application run failed
6:43:42 PM web.1 |  org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourceScriptDatabaseInitializer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'databaseConfig': Injection of aut
6:43:42 PM web.1 |  >  owired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.datasource.url' in value "${spring.datasource.url}"
6:43:42 PM web.1 |      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290) ~[spring-boot-2.6.1.jar!/:2.6.1]
6:43:42 PM web.1 |      at com.discount.discount.DiscountApplication.main(DiscountApplication.java:10) ~[classes!/:na]
6:43:42 PM web.1 |      at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[discount-0.0.1-SNAPSHOT.jar:na]
6:43:42 PM web.1 |      at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[discount-0.0.1-SNAPSHOT.jar:na]
6:43:42 PM web.1 |      at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[discount-0.0.1-SNAPSHOT.jar:na]
6:43:42 PM web.1 |      at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) ~[discount-0.0.1-SNAPSHOT.jar:na]
6:43:42 PM web.1 |  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'databaseConfig': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.datasource.url' in value "${spring.datasource.url}"
6:43:42 PM web.1 |      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:405) ~[spring-beans-5.3.13.jar!/:5.3.13]
6:43:42 PM web.1 |      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431) ~[spring-beans-5.3.13.jar!/:5.3.13]
6:43:42 PM web.1 |  Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.datasource.url' in value "${spring.datasource.url}"
6:43:42 PM web.1 |      at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:180) ~[spring-core-5.3.13.jar!/:5.3.13]

** and here's my files : **

Gradle:

plugins {
   id 'org.springframework.boot' version '2.6.1'
   id 'io.spring.dependency-management' version '1.0.11.RELEASE'
   id 'java'
}

group = 'com.discount'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
   mavenCentral()
}


dependencies {
   implementation 'org.springframework.boot:spring-boot-starter-web'
   testImplementation 'org.springframework.boot:spring-boot-starter-test'
   implementation group: 'javax.persistence', name: 'javax.persistence-api', version: '2.2'
   implementation group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc', version: '2.6.0'
   implementation group: 'org.postgresql', name: 'postgresql', version: '42.3.1'


}

test {
   useJUnitPlatform()
}

data base configuration class :


    @Value("${spring.datasource.url}")
    private String dbUrl;

    @Bean
    public DataSource dataSource() {
        HikariConfig config = new HikariConfig();
        config.setJdbcUrl(dbUrl);
        return new HikariDataSource(config);
    }
}

Total Answers 1

33

Answers 1 : of Error creating bean with name dataSourceScriptDatabaseInitializer defined in class path resource

The exception is telling you that the anycodings_spring bean can't be created because you anycodings_spring haven't defined the property anycodings_spring spring.datasource.url.

If you're using a yml configuration, anycodings_spring (for example in src/main/resources you anycodings_spring have the file application.yml), open it anycodings_spring and add the datasource property under anycodings_spring "spring":

spring:
  datasource:
    url: # db connection url here

If you're using a properties file the anycodings_spring format changes to

spring.datasource.url= # db connection url here

0

2022-09-16T05:05:26+00:00 2022-09-16T05:05:26+00:00Answer Link

mRahman

How to resolve error creating bean with name in Spring Boot?

In order to solve this error, either you need to include the correct Starter POM dependency or manually add the MySQL JDBC JAR file into the classpath. If you are interested, you can see this tutorial to learn more about how to connect a Java application to a database using a MySQL database in this tutorial.

What is error creating bean with name?

BeanCreationException: Error creating bean with name happens when a problem occurs when the BeanFactory creates a bean. If the BeanFactory encounters an error when creating a bean from either bean definition or auto-configuration, the BeanCreationException will be thrown.

How do I fix error creating bean with name Entitymanagerfactory?

I suggest that you just delete the folders named hibernate-core and hibernate-entitymanager from your Maven local repository and Maven will reinstall them.