Context
I follow from docs to connect 2 datasource and use Dockerfiles.
Configure Two DataSources Dockerfiles
Issue
It works if I run by IDE.
But if run by docker, the console will stuck at line Second-level cache disabled
2024-07-18 20:43:30 2024-07-18T13:43:30.455Z INFO 1 --- [demo] [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2024-07-18 20:43:30 2024-07-18T13:43:30.457Z INFO 1 --- [demo] [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1413 ms
2024-07-18 20:43:30 2024-07-18T13:43:30.705Z INFO 1 --- [demo] [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: firstDs]
2024-07-18 20:43:30 2024-07-18T13:43:30.746Z INFO 1 --- [demo] [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.4.9.Final
2024-07-18 20:43:30 2024-07-18T13:43:30.773Z INFO 1 --- [demo] [ main] o.h.c.internal.RegionFactoryInitiator : HHH000026: Second-level cache disabled
How to reproduce
I attach the source demo.zip
I use oracle for example
docker-compose.yml
services:
oracle:
container_name: oracle-db
image: gvenzl/oracle-free:23.4-slim-faststart
environment:
- "ORACLE_PASSWORD=ngocnhan"
ports:
- "1521:1521"
Extract it and run below
docker build -t demo .
docker run -dp 127.0.0.1:8080:8080 demo
Please tell me if I miss something.
Spring version: 3.2.7 Java version: 17 Docker version: 27.0.3 OS: Windows 11
Comment From: wilkinsona
It looks to me like your network configuration is wrong which means that the app running inside the container cannot access the database which is also running inside a container. You could use Docker Compose to start both the database and the app. It will automatically create a network of which both containers are members. You'd then have to update the JDBC URLs that you're using to correctly address the database.
If you have any further questions, please follow up on Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.
Comment From: ngocnhan-tran1996
@wilkinsona
I don't think so. If spring cannot access the database, it will be throw execption. But it locks at line Second-level cache disabled.
I also try with Spring version 3.3.1 and it works
Comment From: wilkinsona
That's not the behaviour that I see. When the DB isn't available, 3.3.1 gets stuck at the same place:
docker run -p 127.0.0.1:8080:8080 demo
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.3.1)
2024-07-18T16:03:41.493Z INFO 1 --- [demo] [ main] com.example.demo.DemoApplication : Starting DemoApplication v0.0.1-SNAPSHOT using Java 17.0.11 with PID 1 (/BOOT-INF/classes started by root in /)
2024-07-18T16:03:41.511Z INFO 1 --- [demo] [ main] com.example.demo.DemoApplication : No active profile set, falling back to 1 default profile: "default"
2024-07-18T16:03:42.295Z INFO 1 --- [demo] [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2024-07-18T16:03:42.310Z INFO 1 --- [demo] [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 4 ms. Found 0 JPA repository interfaces.
2024-07-18T16:03:42.316Z INFO 1 --- [demo] [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2024-07-18T16:03:42.318Z INFO 1 --- [demo] [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 0 ms. Found 0 JPA repository interfaces.
2024-07-18T16:03:43.088Z INFO 1 --- [demo] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http)
2024-07-18T16:03:43.104Z INFO 1 --- [demo] [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2024-07-18T16:03:43.104Z INFO 1 --- [demo] [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.25]
2024-07-18T16:03:43.202Z INFO 1 --- [demo] [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2024-07-18T16:03:43.205Z INFO 1 --- [demo] [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1545 ms
2024-07-18T16:03:43.452Z INFO 1 --- [demo] [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: firstDs]
2024-07-18T16:03:43.509Z INFO 1 --- [demo] [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.5.2.Final
2024-07-18T16:03:43.545Z INFO 1 --- [demo] [ main] o.h.c.internal.RegionFactoryInitiator : HHH000026: Second-level cache disabled
I just left this container running and it eventually failed:
2024-07-18T16:03:43.545Z INFO 1 --- [demo] [ main] o.h.c.internal.RegionFactoryInitiator : HHH000026: Second-level cache disabled
2024-07-18T16:08:44.463Z ERROR 1 --- [demo] [ main] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: File must exist : /proc/self/task/1/cwd/proc/self/task/1/cwd/proc/self/task/1/cwd/proc/self/task/1/cwd/proc/self/task/1/cwd/proc/self/task/1/cwd/proc/self/task/1/cwd/proc/self/task/1/cwd/proc/self/task/1/cwd/proc/self/task/1/cwd/proc/self/task/1/cwd/proc/self/task/1/cwd/proc/self/task/1/cwd/proc/self/task/1/cwd/proc/self/task/1/cwd/proc/self/task/1/cwd/proc/self/task/1/cwd/proc/self/task/1/cwd/proc/self/task/1/cwd/proc/1/task/1/root/proc/1/task/18/cwd/proc/56/task/74/fdinfo/68
Looking at your Dockerfile, you're installed the app in /. That appears to be caused Hibernate to scan the entire filesystem. If I move the app into /app, it then fails as the DB is inaccessible.
I can't see any signs of a Spring Boot bug here. As I said above, if you require any further assistance please follow up on Stack Overflow.
Comment From: ngocnhan-tran1996
@wilkinsona
Thanks for the answer. This is my bad.