I'm following Amigoscode tutorial Getting Started with Spring Boot and I'm currently trying to connect to my local database, but I get an error:
HHH000342: Could not obtain connection to query metadata
What I've learned is that Hibernate recent version works different, so the tutorial content it out of data. So I was wondering, can use a older version of Hibernate?
I can also be totally wrong about Hibernate. If this is a command error plz give me some information.
spring.datasource.url=jdbc:postgresql://localhost:5432/student
spring.datasource.username=postgres
spring.datasource.password=******
spring.jpa.hibernate.ddl-auto=create-drop
spring.java.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PosterSQLDialect
spring.jpa.properties.hibernate.format_sql=true
NEW ERROR
49.203 ERROR 9572 --- [ main] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
2022-04-06 11:39:49.203 WARN 9572 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
There is no meaning of PosterSQLDialect in configuration of hibernate dialect. It should be PostgreSQLDialect.
Change
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PosterSQLDialect
To
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
Related
I have deployed my spring boot application on PCF (Pivotal Cloud Foundry) cloud and it was running fine since last many days but suddenly from last 24 hours, this application is started crashing in every few minutes.
And getting below errors
[trade-data-service,,,] 15 --- [main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'reactiveHealthIndicatorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/LegacyHealthEndpointCompatibilityConfiguration$LegacyReactiveHealthEndpointCompatibilityConfiguration.class]: Unsatisfied dependency expressed through method 'reactiveHealthIndicatorRegistry' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'reactiveHealthContributorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/ReactiveHealthEndpointConfiguration.class]: Unsatisfied dependency expressed through method 'reactiveHealthContributorRegistry' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'discoveryCompositeHealthContributor' defined in class path resource [org/springframework/cloud/client/CommonsClientAutoConfiguration$DiscoveryLoadBalancerConfiguration.class]: Unsatisfied dependency expressed through method 'discoveryCompositeHealthContributor' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'eurekaHealthIndicator' defined in class path resource [org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration$EurekaHealthIndicatorConfiguration.class]: Unsatisfied dependency expressed through method 'eurekaHealthIndicator' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'eurekaInstanceConfigBean' defined in class path resource [org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean]: Factory method 'eurekaInstanceConfigBean' threw exception; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'vcap.application.uris[0]' in value "${vcap.application.uris[0]}"
[trade-data-service,,,] 15 --- [main] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
[trade-data-service,,,] 15 --- [main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
If I check health of application using /actuator/health then it return application status is UP.
What could be the reason ?
Please help
I am using a shutdown hook to do some database operation before application is closed.
Runtime.getRuntime().addShutdownHook(shutdownDaemonHook);
I am adding my shutdown hook to RunTime like this. Application Context should be closed after this thread finishes its job but in the middle of this job, application context is closed and giving JPA is closed exception.
2022-10-12 16:51:54.217 INFO 25468 --- [tomcat-shutdown] o.s.b.w.e.tomcat.GracefulShutdown : Graceful shutdown complete
2022-10-12 16:51:54.240 WARN 25468 --- [extShutdownHook] o.s.b.f.support.DisposableBeanAdapter : Destroy method 'close' on bean with name 'mappedBusReader' threw an exception: java.io.IOException: Unable to close the file
2022-10-12 16:51:54.244 INFO 25468 --- [extShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2022-10-12 16:51:54.247 INFO 25468 --- [extShutdownHook] o.s.s.c.ThreadPoolTaskScheduler : Shutting down ExecutorService 'taskScheduler'
2022-10-12 16:51:54.247 INFO 25468 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
as in the logs, you can see JPA is closed.
#EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot create inner bean '(inner bean) of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#3d7314b3': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hikari' defined in class path resource: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker': Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties': Could not bind properties to 'DataSourceProperties' : prefix=spring.datasource, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is java.lang.IllegalStateException: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext has been closed already
is there any way to prevent this ? , Applicatin Context or JPA should not be closed until shutdown hook finishes it job.
I'm using Spring Boot 2.0.6.RELEASE. My application uses the Oracle jdbc driver and works nice with this kind of configuration:
spring.datasource.url=jdbc:oracle:thin:#my-data-server/database
spring.datasource.username=username
spring.datasource.password=pwd
spring.datasource.hikari.maximum-pool-size=10
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
But... When adding actuator, the application fails to start. It seems that the /health endpoint causes this problem (maybe because it is the first bean which needs a datasource?).
The problem is that the datasource can't be instanciate... But it works well without actuator.
Any idea ?
I was wondering if DataSourceHealthIndicatorAutoConfiguration could be the source of the problem: this class has the anotation #AutoConfigureAfter(DataSourceAutoConfiguration.class)... But it seems that Hikari doesn't use this autoconfig class, does it? I see org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari in the stack trace but not DataSourceAutoConfiguration...
**UPDATE : ** I'm using FlyWay
**UPDATE 2 **, This may be a hint: https://github.com/spring-projects/spring-boot/issues/14687
Here is the full stacktrace:
2019-02-08 17:33:38.359 ERROR 14652 --- [ost-startStop-1]
o.s.b.web.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [org.springframework.boot.actuate.health.HealthEndpoint]: Factory method 'healthEndpoint' threw exception;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration': Bean instantiation via constructor failed;
nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration$$EnhancerBySpringCGLIB$$8065d973]: Constructor threw exception;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Post-processing of FactoryBean's singleton object failed;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception;
nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2019-02-08 17:33:38.381 INFO 14652 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2019-02-08 17:33:38.416 WARN 14652 --- [ost-startStop-1] o.a.c.loader.WebappClassLoaderBase : The web application [ROOT] appears to have started a thread named [spring.cloud.inetutils] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)
2019-02-08 17:33:38.419 WARN 14652 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2019-02-08 17:33:38.437 INFO 14652 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-02-08 17:33:38.445 ERROR 14652 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (the profiles dev are currently active).
Process finished with exit code 0
when I run this error comes pleas help me to solve this
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-02-11 10:53:55.839 ERROR 8804 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
APPLICATION FAILED TO START
Description:
Field userDao in com.example.spring.security.api.service.UserServiceImpl required a bean named 'entityManagerFactory' that could not be found.
Action:
Consider defining a bean named 'entityManagerFactory' in your configuration.
What annotations are you using? Could be that you are using some annotation that tells Spring boot to not use some autoconfiguration.
You probably want HibernateJpaAutoConfiguration to run.
When I add below dependency to pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
Below error comes
2018-05-31 12:02:38.217 INFO 1416 --- [ost-startStop-1]
j.LocalContainerEntityManagerFactoryBean : Initialized JPA
EntityManagerFactory for persistence unit 'default' 2018-05-31
12:02:39.233 ERROR 1416 --- [ost-startStop-1]
o.s.b.c.embedded.tomcat.TomcatStarter : Error starting Tomcat
context. Exception:
org.springframework.beans.factory.UnsatisfiedDependencyException.
Message: Error creating bean with name
'registerCorePageControllerServlet' defined in
com.amd.apps.employee.cloud.AddonApplication:
Unsatisfied dependency expressed through method
'registerCorePageControllerServlet' parameter 1; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'authenticationContextImpl' defined in
URL
[jar:file:/C:/Users/shiv/AppData/Local/Temp/employee.cloud-1.0.0.jar-spring-boot-libs-1766ddea-c2ae-424e-9565-d00395eb0d5c/core.cloud-1.0.0.jar!/com/amd/apps/cloud/service/common/AuthenticationContextImpl.class]:
Unsatisfied dependency expressed through constructor parameter 3;
nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'companyServiceImpl' defined in URL
[jar:file:/C:/Users/shiv/AppData/Local/Temp/employee.cloud-1.0.0.jar-spring-boot-libs-1766ddea-c2ae-424e-9565-d00395eb0d5c/core.cloud-1.0.0.jar!/com/amd/apps/cloud/service/directory/impl/CompanyServiceImpl.class]:
Unsatisfied dependency expressed through constructor parameter 1;
nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type
'com.atlassian.connect.spring.AtlassianHostRepository' available:
expected at least 1 bean which qualifies as autowire candidate.
Dependency annotations: {}
However if i remove this dependency, everything works perfectly. Redis service is configured, running and accessible. However i see below messages as well, which i do not see during normmal execution
2018-05-31 12:02:28.955 INFO 1416 --- [ main]
.s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data
modules found, entering strict repository configuration mode!
2018-05-31 12:02:29.071 INFO 1416 --- [ main]
.RepositoryConfigurationExtensionSupport : Spring Data JPA - Could not
safely identify store assignment for repository candidate interface
com.atlassian.connect.spring.AtlassianHostRepository. 2018-05-31
12:02:29.171 INFO 1416 --- [ main]
.s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data
modules found, entering strict repository configuration mode!
The problem is caused by RedisRepositoriesAutoConfiguration. It registers EnableRedisRepositories repeatedly only with default config, which with empty basePackages.
To solve the problem, you could exclude RedisRepositoriesAutoConfiguration by:
#SpringBootApplication(
exclude = { RedisRepositoriesAutoConfiguration.class })