Springboot Application startup failed due to OutOfMemoryError: Java heap space (Unable to create entityManagerFactory Bean) - spring-boot

We are using spring boot version 2.1.3 with sprintboot jpa started.
Application is failing at startup with logs:
Injecting ScanOptions
[org.hibernate.boot.archive.scan.internal.StandardScanOptions#78d49939]
into BootstrapContext; was
[org.hibernate.boot.archive.scan.internal.StandardScanOptions#21f27bb5]
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
java.lang.OutOfMemoryError: Java heap space
Heap memory: 512 MB.
Hibernate properties :
spring.jpa:
database: ORACLE
show-sql: true
generate-ddl: false
hibernate:
ddl-auto: none
properties:
hibernate:
dialect: org.hibernate.dialect.Oracle10gDialect
id:
new_generator_mappings: true
show_sql: false
connection:
autocommit: true
release_mode: after_transaction
Using ojdbc7.
We are getting this issue intermittently.

This error is purely related to heap memory. After increasing heap memory at startup, It worked well.

Related

spring boot quartz not starting in clustered mode

My spring boot application always starts quartz in non clustered mode.
Below is my configurations:
spring.quartz:
job-store-type: jdbc
jdbc:
initialize-schema: never
properties:
org:
quartz:
scheduler:
instanceId: AUTO
instanceName: myQuartzScheduler
job-store:
dataSource: quartzDataSource
class: org.springframework.scheduling.quartz.LocalDataSourceJobStore
driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
useProperties: false
tablePrefix: QRTZ_
misfireThreshold: 60000
clusterCheckinInterval: 5000
isClustered: true
threadPool:
class: org.quartz.simpl.SimpleThreadPool
threadCount: 10
threadPriority: 5
threadsInheritContextClassLoaderOfInitializingThread: true
added dependency
spring-boot-starter-quartz
have quartz job and trigger in place. Application starts and the job gets fired as per the cron. but quartz always starts in non clustered mode:
2022-07-29 11:10:09.810 INFO 86257 --- [ main] o.s.s.quartz.LocalDataSourceJobStore : JobStoreCMT initialized.
2022-07-29 11:10:09.810 INFO 86257 --- [ main] org.quartz.core.QuartzScheduler : Scheduler meta-data: Quartz Scheduler (v2.3.2) 'myQuartzScheduler' with instanceId 'NON_CLUSTERED'
Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
NOT STARTED.
Currently in standby mode.
Number of jobs executed: 0
Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
Using job-store 'org.springframework.scheduling.quartz.LocalDataSourceJobStore' - which supports persistence. and is not clustered.
What did I miss folks? I need to start quartz in clustered mode. Any help, appreciated. Thank you.
You have probably followed this article on how to build the clustered job scheduler.
In your case however you have used the
job-store:
class: org.springframework.scheduling.quartz.LocalDataSourceJobStore
The property however org.quartz.jobStore.isClustered: true that you later use, does not exist in common spring boot properties. It is a specific property, that is used from a specific JobStore, namely the org.quartz.impl.jdbcjobstore.JobStoreTX
Referenced doc
If you don't have any further conflicts in your properties, just changing into the following should fix the issue.
job-store:
class: org.quartz.impl.jdbcjobstore.JobStoreTX
The hint from #Panagiotis Bougioukos helped.
I had to change the configuration job-store: to jobStore: then the class class: org.quartz.impl.jdbcjobstore.JobStoreTX was honoured and Quartz started in clustered mode.
Finally
spring.quartz:
job-store-type: jdbc
jdbc:
initialize-schema: never
properties:
org:
quartz:
scheduler:
instanceId: AUTO
instanceName: myQuartzScheduler
jobStore:
dataSource: quartzDataSource
.
.
dataSource.quartzDataSource:
driver: com.mysql.cj.jdbc.Driver
URL: jdbc:mysql://${database.host:localhost}:${database.port:3306}/${database.name:mySchema}
user: myUser
password: ******
provider: hikaricp
and defining the quartzDataSource helped.

Driver claims to not accept jdbcUrl, ${JDBC_DATABASE_URL} when setting externalized config

I'm using the instructions in this Heroku article to attempt to externalize database strings for a hosted Postgres DB. When I use the literal string, I can connect with no issues. However, when I attempt to use the externalized variable ${JDBC_DATABASE_URL}, I'm getting the error message:
2022-06-17 17:30:17.063 WARN 7712 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is java.lang.RuntimeException: Driver org.postgresql.Driver claims to not accept jdbcUrl, ${JDBC_DATABASE_URL}
It looks like it's interpreting the externalized variable itself as a literal string, but I have no idea why. I haven't included any other config files because it is currently working with the database string, but I can attach them if need be. Any ideas?

ActivemQ Artemis with MQTT protocol

[AnnotationConfigEmbeddedWebApplicationContext:559] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedActiveMQ' defined in class path resource [com/els/galaxy/gateway/ArtemisConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.apache.activemq.artemis.core.protocol.mqtt.MQTTProtocolManagerFactory.stripPasswordParameters(Ljava/util/Map;)V
[LocalContainerEntityManagerFactoryBean:597] - Closing JPA EntityManagerFactory for persistence unit 'readPersistenceUnit'
=[LocalContainerEntityManagerFactoryBean:597] - Closing JPA EntityManagerFactory for persistence unit 'writePersistentUnit'
[session:167] - node0 Stopped scavenging
[ContextHandler:1045] - Stopped o.s.b.c.e.j.JettyEmbeddedWebAppContext#7bebe5de{application,/galaxy-gateway,[file:///C:/Users/basireddym/AppData/Local/Temp/jetty-docbase.7636853341168462882.86/],UNAVAILABLE}
[AutoConfigurationReportLoggingInitializer:102] -

Unable to instantiate H2

I am trying to setup H2 as in-memory database. I have configured it as :
spring:
profiles: qa
datasource:
#url: jdbc:h2:mem:testdb;MODE=MySQL;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS "public"
jdbc-url: jdbc:mysql://localhost:3306/lisdashboard
username: '#lisdashboard.db.username#'
password: '#lisdashboard.db.password#'
h2:
console:
path: /admin/h2-console
However I am getting this error when I try to run it
- Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is java.lang.RuntimeException: Driver org.h2.Driver claims to not accept jdbcUrl, jdbc:mysql://localhost:3306/lisdashboard
-
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
- Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]:
Invocation of init method failed; nested exception is java.lang.RuntimeException: Driver org.h2.Driver claims to not accept jdbcUrl, jdbc:mysql://localhost:3306/lisdashboard
I am not sure why it doesn't accept the jdbc url, Is there any issue in the format of my confg?
You are using a MySQL jdbc url to try to connect to an H2 instance.
You need to replace your configuration to use the url jdbc:h2:mem: instead of the one you are using now jdbc:mysql://localhost:3306/lisdashboard.
If you want to use a different type of H2 instance, check the documentation to see the alternatives (such a file instance).
If you want to use H2 your config should look like:
spring:
profiles: qa
datasource:
url: jdbc:h2:mem:testdb;MODE=MySQL;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS "public"
username: '#lisdashboard.db.username#'
password: '#lisdashboard.db.password#'
h2:
console:
path: /admin/h2-console
You had a # infront of the URL and # is a comment in YAML

Different image behavior in Google Container Registry vs locally (packaged Spring Boot app)

We have a Spring Boot application (multiple micro-services), packaged with Google Container Builder and published to the registry. Our cloudbuild.yaml looks like this:
steps:
- name: 'gcr.io/cloud-builders/java/gradle'
id: 'java-build'
args: ['build']
- name: 'gcr.io/cloud-builders/docker'
args: ['build',
'-t', 'gcr.io/$PROJECT_ID/api-auth:$COMMIT_SHA',
'-t', 'gcr.io/$PROJECT_ID/api-auth:latest',
'-f', './api-auth/Dockerfile', './api-auth']
waitFor: ['java-build']
- name: 'gcr.io/cloud-builders/docker'
args: ['build',
'-t', 'gcr.io/$PROJECT_ID/api-user:$COMMIT_SHA',
'-t', 'gcr.io/$PROJECT_ID/api-user:latest',
'-f', './api-user/Dockerfile', './api-user']
waitFor: ['java-build']
images:
- 'gcr.io/$PROJECT_ID/api-auth:$COMMIT_SHA'
- 'gcr.io/$PROJECT_ID/api-auth:latest'
- 'gcr.io/$PROJECT_ID/api-user:$COMMIT_SHA'
- 'gcr.io/$PROJECT_ID/api-user:latest'
which is called by a trigger on push into the repository on GitHub.
If I run this locally:
container-builder-local --dryrun=false .
resulting images run fine, e.g.:
docker run -e "SPRING_PROFILES_ACTIVE=development" -p 9000:9000 gcr.io/.../api-auth:latest
but when the image is built in the cloud with the Container Builder, the application doesn't work and fails with error that never ocurred before.
Even when pulled:
gcloud docker -- pull gcr.io/.../api-auth:latest
and run locally the new error stops the application from loading:
2017-10-11 16:35:27.661 WARN 5 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webSecurityConfig': Unsatisfied dependency expressed through field 'authenticationManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationManager' defined in class path resource [org/springframework/boot/autoconfigure/security/AuthenticationManagerConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.authentication.AuthenticationManager]: Factory method 'authenticationManager' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'OAuth2Config': Unsatisfied dependency expressed through field 'authenticationManager'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'authenticationManager': Requested bean is currently in creation: Is there an unresolvable circular reference?
2017-10-11 16:35:27.663 INFO 5 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2017-10-11 16:35:27.676 INFO 5 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2017-10-11 16:35:27.718 INFO 5 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-10-11 16:35:27.730 ERROR 5 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
The dependencies of some of the beans in the application context form a cycle:
webSecurityConfig (field private org.springframework.security.authentication.AuthenticationManager com.project.auth.config.WebSecurityConfig.authenticationManager)
┌─────┐
| authenticationManager defined in class path resource [org/springframework/boot/autoconfigure/security/AuthenticationManagerConfiguration.class]
↑ ↓
| OAuth2Config (field private org.springframework.security.authentication.AuthenticationManager com.project.auth.config.OAuth2Config.authenticationManager)
└─────┘
This only happens when the image goes through the Cloud Container Builder - neither the local one, nor with a local gradle build.
Could this possibly be a problem in the cloud, or am I missing something trivial?
I have also filed an issue on GitHub, but since it's a broader problem along with the Spring Boot nature of the application, I thought I'd ask here to see if it rings any bell.

Resources