Spring Boot and Hikari Data Source, server shutting down - spring-boot

I'm writing and application (Angula Dart for front end, Spring Boot for back end) and I have a backbone of functionality already up. I'm facing an issue now, time to tome (can't say if there is a specific timing or if is pure random) the application shutdown itself.
[ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2021-12-14 18:11:27.551 INFO 278601 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2021-12-14 18:11:27.568 INFO 278601 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
Before those log line the application is working without any problems (there is a certai amount of inactivity of the server, it recives few requestes over the day).
This is the command i use to launch the app
java -Duser.country=IT -Duser.language=it -Dserver.port=4499 -jar whServer.jar > whServer.log 2> whServer-error.log&
Before the shtdown there are no applicative errors

Related

Not working :: spring.jpa.hibernate.ddl-auto=update

I am trying to create multitenant application with single db and seperate schemas for tenants. And I don't want to loose my data after every startup. This is my application.properties file
logging.level.root=info
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:multi-tenant
spring.jpa.hibernate.ddl-auto=update
spring.liquibase.change-log=classpath:db/changelog/changelog-master.xml
And here is my logs
Connected to the target VM, address: '127.0.0.1:53999', transport: 'socket'
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.2)
2022-08-11 13:02:28.342 INFO 25732 --- [ main] c.l.multitenant.MultiTenantApplication : Starting MultiTenantApplication using Java 18.0.1.1 on Manu with PID 25732 (D:\JAVA\multi-tenant - updated\target\classes started by itsma in D:\JAVA\multi-tenant - updated)
2022-08-11 13:02:28.342 INFO 25732 --- [ main] c.l.multitenant.MultiTenantApplication : No active profile set, falling back to 1 default profile: "default"
2022-08-11 13:02:29.534 INFO 25732 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-08-11 13:02:29.613 INFO 25732 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 53 ms. Found 1 JPA repository interfaces.
2022-08-11 13:02:30.507 INFO 25732 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-08-11 13:02:30.522 INFO 25732 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-08-11 13:02:30.522 INFO 25732 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.65]
2022-08-11 13:02:30.742 INFO 25732 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-08-11 13:02:30.742 INFO 25732 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2321 ms
2022-08-11 13:02:30.993 INFO 25732 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-08-11 13:02:31.286 INFO 25732 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-08-11 13:02:31.302 INFO 25732 --- [ main] o.s.b.a.h2.H2ConsoleAutoConfiguration : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:multi-tenant'
2022-08-11 13:02:31.893 INFO 25732 --- [ main] liquibase.database : Set default schema name to PUBLIC
2022-08-11 13:02:32.253 INFO 25732 --- [ main] liquibase.lockservice : Successfully acquired change log lock
2022-08-11 13:02:32.929 INFO 25732 --- [ main] liquibase.changelog : Creating database history table with name: PUBLIC.DATABASECHANGELOG
2022-08-11 13:02:32.929 INFO 25732 --- [ main] liquibase.changelog : Reading from PUBLIC.DATABASECHANGELOG
Running Changeset: db/changelog/changelog-v1.0.xml::1::manu
2022-08-11 13:02:33.102 INFO 25732 --- [ main] liquibase.changelog : SQL in file db/changelog/data/data.sql executed
2022-08-11 13:02:33.102 INFO 25732 --- [ main] liquibase.changelog : ChangeSet db/changelog/changelog-v1.0.xml::1::manu ran successfully in 32ms
2022-08-11 13:02:33.117 INFO 25732 --- [ main] liquibase.lockservice : Successfully released change log lock
2022-08-11 13:02:33.321 INFO 25732 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-08-11 13:02:33.384 INFO 25732 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.10.Final
2022-08-11 13:02:33.525 INFO 25732 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-08-11 13:02:33.682 INFO 25732 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2022-08-11 13:02:34.138 INFO 25732 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-08-11 13:02:34.138 INFO 25732 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-08-11 13:02:34.530 WARN 25732 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2022-08-11 13:02:35.064 INFO 25732 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 1 endpoint(s) beneath base path '/actuator'
2022-08-11 13:02:35.143 INFO 25732 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-08-11 13:02:35.174 INFO 25732 --- [ main] c.l.multitenant.MultiTenantApplication : Started MultiTenantApplication in 7.407 seconds (JVM running for 8.296)
2022-08-11 13:02:37.086 INFO 25732 --- [nio-8080-exec-7] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-08-11 13:02:37.086 INFO 25732 --- [nio-8080-exec-7] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2022-08-11 13:02:37.087 INFO 25732 --- [nio-8080-exec-7] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
Why is ddl-auto=update not working?
You use an in memory database configuration.
This means that when the application starts up an embedded database will be created not in permanent memory but in RAM.
This also means that when the application is shut down the memory it took in RAM is cleaned, therefore any information relative with this database is also lost.
H2 database offers another configuration in the url which will make sure that the data that database holds, is not stored in RAM but in permanent storage HDD. This way the application could be shut down and the data which the database contained, will not be lost.
The database however will stop functioning when the application is shut down, as the process that runs the database belongs to the main process of starting your application. But when the application starts up again and database process is started also, the database will see all the data that it contained before the application was shutdown.
The config is the following:
spring.datasource.url= jdbc:h2:/data/multi-tenant;AUTO_SERVER=TRUE
Multiple processes can access the same database without having to
start the server manually. To do that, append ;AUTO_SERVER=TRUE to the
database URL. You can use the same database URL independent of whether
the database is already open or not. This feature doesn't work with
in-memory databases.
Use the same URL for all connections to this database. Internally,
when using this mode, the first connection to the database is made in
embedded mode, and additionally a server is started internally (as a
daemon thread). If the database is already open in another process,
the server mode is used automatically. The IP address and port of the
server are stored in the file .lock.db, that's why in-memory databases
can't be supported.
The application that opens the first connection to the database uses
the embedded mode, which is faster than the server mode. Therefore the
main application should open the database first if possible. The first
connection automatically starts a server on a random port. This server
allows remote connections, however only to this database (to ensure
that, the client reads .lock.db file and sends the random key that is
stored there to the server). When the first connection is closed, the
server stops. If other (remote) connections are still open, one of
them will then start a server (auto-reconnect is enabled
automatically).
All processes need to have access to the database files. If the first
connection is closed (the connection that started the server), open
transactions of other connections will be rolled back (this may not be
a problem if you don't disable autocommit). Explicit client/server
connections (using jdbc:h2:tcp:// or ssl://) are not supported. This
mode is not supported for in-memory databases.
H2 Documentation

NullPointerException while starting Spring Shell on Heroku worker node

Recently we are facing an issue that we cannot start our Spring Shell app on our Heroku worker node anymore. Directly after the shell app has started the console just prints java.lang.NullPointerException a million times (like there is kina a loop that is trying to instantiate a bean or something which is failing all the time).
Here is an excerpt:
Running /env.sh java -jar ops.jar on ⬢ foo... up, worker.8633 (Standard-1X)
2022-03-04 07:44:37.221 INFO 5 --- [ main] ...Application : Starting Application v1.0.0-SNAPSHOT using Java 11.0.11 on 2e0b87b1-cecd-4720-8c27-4d39afba9615 with PID 5 (/ops.jar started by u27375 in /)
2022-03-04 07:44:37.226 INFO 5 --- [ main] ...Application : No active profile set, falling back to 1 default profile: "default"
2022-03-04 07:44:38.012 INFO 5 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-03-04 07:44:38.129 INFO 5 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 110 ms. Found 10 JPA repository interfaces.
2022-03-04 07:44:38.886 INFO 5 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-03-04 07:44:38.948 INFO 5 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.5.Final
2022-03-04 07:44:39.127 INFO 5 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-03-04 07:44:39.547 INFO 5 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-03-04 07:44:39.929 INFO 5 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-03-04 07:44:39.948 INFO 5 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2022-03-04 07:44:41.089 INFO 5 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-03-04 07:44:41.098 INFO 5 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-03-04 07:44:42.590 INFO 5 --- [ main] ...Application : Started Application in 5.939 seconds (JVM running for 6.39)
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
...
We use Spring Boot v2.6.4 and Spring Shell v2.0.1.RELEASE. The Spring Shell app is containerized (Docker) and we usually start it with:
heroku run --type worker -a foo -- /env.sh java -jar ops.jar
Does anyone of you guys have some tips or something on how to solve or even how to debug this further, i.e., to print the whole stacktrace of the exception?
Could this be something related to JLine in a way that in cannot be used in a Docker container together with Heroku?! However, this worked like a charm in the past.
As said, we appreciate any hint or tip on how to debug this further.
Cheers

Grails 4 - Google Cloud Platform deployment keeps restarting

My Grails 4 application, deployed to GCP appears to be trying to start up after being deployed but never comes up properly. Application requests return a 500 response. There are no errors or clues with DEBUG log level output at the root level.
The same application runs fine locally in development mode.
The production configuration is as per the Grails 3 deployment (to GCP) guide except for the adjustments that were necessary to make it work for Grails 4/Java 11.
Most of the bootstrapping appears to carry out as expected;
Spring Security configures successfully
Spring Security REST configures successfully
Spring beans are registered
Connects to Cloud SQL instance
Database schema is created (by Liquibase)
Plugins are loaded successfully
Then it gets to the following familiar lines of output logging;
INFO --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
INFO --- [main] o.a.coyote.http11.Http11NioProtocol : Initializing ProtocolHandler ["http-nio-8080"]
INFO --- [main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
INFO --- [main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.17]
and restarts..
while normally, the next phase of bootstrapping (happens locally) would be;
[restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
[restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 42018 ms
Probably a long shot question but any level of clues or suggestions would be much appreciated.
I've run out of doors to open. :-(
You could try to update Tomcat version just in case.
But looking at Grails documentation:
https://docs.grails.org/latest/guide/upgrading.html
There's some configuration made when you upgrade to Grails 4 from
Grails 3.3.x to prevents the server from restarting when views or
message bundles are changed.
Either modifying a gsp in Grails 4 M2 cause the application to restart.
https://github.com/grails/grails-core/issues/11284

Spring / IntelliJ doesn't clear session data on stop

I ran in a weird situation I never had before.
I've got a spring boot application running on intelliJ on ubuntu 18.
My spring boot application runs in a dev environment connected to a h2 in memory database. I have a session based login with spring security.
The weird thing is if after I stopped and restarted the application I am still logged in. And even if I completely restart IntelliJ the session is not cleared. Even the database keeps its state and is not getting dropped.
Only if I restart the whole system everything will be cleared.
Inside my application.properties there are no special properties set.
Everything's on default.
If I stop the application the following console output comes up:
2018-12-22 11:11:19.385 INFO 10000 --- [ Thread-35] ConfigServletWebServerApplicationContext : Closing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#73abcbfa: startup date [Sat Dec 22 11:11:00 CET 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext#12e6f48a
2018-12-22 11:11:19.391 INFO 10000 --- [ Thread-35] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2018-12-22 11:11:19.391 INFO 10000 --- [ Thread-35] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans
2018-12-22 11:11:19.395 INFO 10000 --- [ Thread-35] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2018-12-22 11:11:19.395 INFO 10000 --- [ Thread-35] .SchemaDropperImpl$DelayedDropActionImpl : HHH000477: Starting delayed drop of schema as part of SessionFactory shut-down'
2018-12-22 11:11:19.415 WARN 10000 --- [ Thread-35] o.s.b.f.support.DisposableBeanAdapter : Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.h2.jdbc.JdbcSQLException:Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL) [90121-197]
2018-12-22 11:11:19.417 INFO 10000 --- [ Thread-35] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2018-12-22 11:11:19.419 INFO 10000 --- [ Thread-35] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
Process finished with exit code 130 (interrupted by signal 2: SIGINT)
https://github.com/spring-projects/spring-boot/wiki/spring-boot-1.3.0-m3-release-notes
Update Tomcat, Jetty and Undertow to serialize session data when the
application is stopped and load it again when the application
restarts. Persistent session are opt-in; either by setting
persistentSession on the ConfigurableEmbeddedServletContainer or by
using the property server.session.persistent=true (Persistent sessions
are enabled by default with Devtools).
In spring boot 2, the property is:
server.servlet.session.persistent=false # Whether to persist session data between restarts.
I suppose you are talking about web login via browser (or REST-client). Also I suppose you're using default web security settings.
Then your login request creates a cookie with session id which is returned to browser and is being used in next requests until you close browser.

Spring boot with spring.data.mongodb.uri=mongodb://otherhost/test

I developed a Spring boot application with MongoDB. While the MongoDB in the localhost, it works fine, but when the MongoDB is in different the server, I changed the setting in application.properties as
spring.data.mongodb.uri=mongodb://192.168.7.31/gcp
spring.data.mongodb.username=xxx
spring.data.mongodb.password=xxxxxxx
the application faileds as it still looks for the mongoDB in localhost
2017-01-04 11:47:46.161 INFO 15610 --- [ main] org.mongodb.driver.cluster : Adding discovered server localhost:27017 to client view of cluster
2017-01-04 11:47:46.218 INFO 15610 --- [localhost:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server localhost:27017
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.connection.SocketStream.open(SocketStream.java:63) ~[mongodb-driver-core-3.2.2.jar:na]
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:114) ~[mongodb-driver-core-3.2.2.jar:na]
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorR
Anyone can help to tell me how to set the parameters?

Resources