Spring Boot - rmi connection error during initialization - java

I have a problem with starting the Spring Boot application created by spring initializer.
mvn command stacktrace
[DEBUG] Application argument(s): --spring.application.admin.enabled=true --spring.application.admin.jmx-name=org.springframework.boot:type=Admin,name=SpringApplication
[DEBUG] Environment variable(s):
[DEBUG] Connecting to local MBeanServer at port 9001
[DEBUG] Waiting for spring application to start...
[DEBUG] MBean server at port 9001 is not up yet...
[DEBUG] Spring application is not ready yet, waiting 500ms (attempt 1)
[DEBUG] Connected to local MBeanServer at port 9001
[DEBUG] Waiting for spring application to start...
[DEBUG] Spring application is not ready yet, waiting 500ms (attempt 1)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.5.6)
2021-11-01 12:40:43.639 INFO 37902 --- [ main] com.example.demo1.Demo1Application : Starting Demo1Application using Java 17 on dj-legion with PID 37902 (/home/dj/Documents/demo1/target/classes started by dj in /home/dj/Documents/demo1)
2021-11-01 12:40:43.642 INFO 37902 --- [ main] com.example.demo1.Demo1Application : No active profile set, falling back to default profiles: default
[DEBUG] Spring application is not ready yet, waiting 500ms (attempt 2)
2021-11-01 12:40:44.185 INFO 37902 --- [ main] com.example.demo1.Demo1Application : Started Demo1Application in 0.947 seconds (JVM running for 1.53)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.931 s
[INFO] Finished at: 2021-11-01T12:40:44+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.5.6:start (default-cli) on project demo1: Could not figure out if the application has started: Failed to connect to MBean server at port 9001: Could not invoke shutdown operation: Connection refused to host: 127.0.0.1; nested exception is:
[ERROR] java.net.ConnectException: Connection refused
Do you have any idea how to fix this kind of error? I've tried with a lower java/maven/spring-boot versions but without success.

The solution is trivial. I forgot about web dependency and the application has been finished immediately.
Just add to your pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

Related

When I start my spring boot application, my database is not initiating

I have one spring-boot test application in which I provide the following configuration in application.yml file. when I start my server using mvn test, it doesn't initiate the database connection, what can be the issue here? Am I missing any dependency in pom.xml?
spring.datasource.driverClassName = com.ibm.db2.jcc.DB2Driver
spring.datasource.url=jdbc:db2://<fullURL>
spring.datasource.username = <uname>
spring.datasource.password = <password>
Following are my dependencies related to spring-boot
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
Here are my boot logs in which I don't see the database connection logs
[INFO] Running com.test.installments.customers.data.processor.test.RunTest
11:11:30.823 [main] INFO o.s.b.t.c.SpringBootTestContextBootstrapper - Neither #ContextConfiguration nor #ContextHierarchy found for test class [com.test.in
stallments.customers.data.processor.test.RunTest], using SpringBootContextLoader
11:11:30.829 [main] INFO o.s.t.c.s.AbstractContextLoader - Could not detect default resource locations for test class [com.test.installments.customers.data.
processor.test.RunTest]: no resource found for suffixes {-context.xml, Context.groovy}.
11:11:30.976 [main] INFO o.s.b.t.c.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]:
[org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springfr
amework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecut
ionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.we
b.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframe
work.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.te
st.context.event.ApplicationEventsTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.tes
t.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.co
ntext.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
11:11:30.992 [main] INFO o.s.b.t.c.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.support.DirtiesContextBefor
eModesTestExecutionListener#162be91c, org.springframework.test.context.event.ApplicationEventsTestExecutionListener#2488b073, org.springframework.boot.test.mock.mo
ckito.MockitoTestExecutionListener#1c9f0a20, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener#55787112, org.springfra
mework.test.context.support.DirtiesContextTestExecutionListener#1cd201a8, org.springframework.test.context.transaction.TransactionalTestExecutionListener#7db82169,
org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener#1992eaf4, org.springframework.test.context.event.EventPublishingTestExecutionListener#f74e83
5, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener#3276732, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionLi
stener#3f28bd56, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener#31e3250d, org.springframework.boot.test.aut
oconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener#19fe4644, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListe
ner#21d8bcbe, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener#5be067de]
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.5.3)
11:11:31.362 [main] INFO c.m.i.c.data.processor.test.RunTest - Starting RunTest using Java 11.0.8 on test with PID 17676 (started by test in C:\git\c
ustomers-data-processor-tests)
11:11:31.362 [main] INFO c.m.i.c.data.processor.test.RunTest - The following profiles are active: dev
11:11:31.446 [main] INFO c.m.i.c.data.processor.test.RunTest - Started RunTest in 0.422 seconds (JVM running for 1.403)
-----------Databse driver name---------- com.ibm.db2.jcc.DB2Driver
11:11:32.161 [main] DEBUG com.intuit.karate.Suite - [config] classpath:karate-config.js
11:11:32.858 [main] INFO com.intuit.karate - karate.env system property was: null
11:11:32.932 [main] INFO com.intuit.karate - [print] Total number of rows
---------------------------------------------------------
feature: classpath:com/test/installments/customers/data/processor/test/fileuload/uploadfile.feature
Couple of things I note:
You are mentioning application.yml but the format of the file is properties
You need to add the Driver in your dependencies for Spring Boot to pick up as well.
If you are running test, and have an applicatio.yml in src/test/resources, it will override the one in src/main/resources

Why spring application is not able to connect to couchbase when running using docker compose

I am trying to run my spring boot application using the docker-compose file but the service running inside the docker container is not able to connect to the database container.
Below is the exception stack trace from docker-compose logs
couchbase-demo | Starting Couchbase Server -- Web UI available at http://<ip>:8091
couchbase-demo | and logs available in /opt/couchbase/var/lib/couchbase/logs
couchbase-demo |
tech-blog | LOGBACK: No context given for c.q.l.core.rolling.SizeAndTimeBasedRollingPolicy#589446616
tech-blog |
tech-blog | . ____ _ __ _ _
tech-blog | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
tech-blog | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
tech-blog | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
tech-blog | ' |____| .__|_| |_|_| |_\__, | / / / /
tech-blog | =========|_|==============|___/=/_/_/_/
tech-blog | :: Spring Boot :: (v2.2.4.RELEASE)
tech-blog |
tech-blog | 01:33:40.468 [main] INFO com.tech.blog.TechBlogApplication - Starting TechBlogApplication v0.0.2-SNAPSHOT on bf6509f5200d with PID 1 (/opt/tech/techblog.jar started by root in /opt/tech)
tech-blog | 01:33:40.477 [main] DEBUG com.tech.blog.TechBlogApplication - Running with Spring Boot v2.2.4.RELEASE, Spring v5.2.3.RELEASE
tech-blog | 01:33:40.477 [main] INFO com.tech.blog.TechBlogApplication - No active profile set, falling back to default profiles: default
^CGracefully stopping... (press Ctrl+C again to force)
Stopping tech-blog ... done
Stopping couchbase-demo ... done
srinathkavuri#Srinaths-MBP TechBlog % docker logs couchbase-demo
Starting Couchbase Server -- Web UI available at http://<ip>:8091
and logs available in /opt/couchbase/var/lib/couchbase/logs
Waiting for Couchbase Server to start....% srinathkavuri#Srinaths-MBP TechBlog % docker-compose up
Starting couchbase-demo ... done
Starting tech-blog ... done
Attaching to couchbase-demo, tech-blog
couchbase-demo | Starting Couchbase Server -- Web UI available at http://<ip>:8091
couchbase-demo | and logs available in /opt/couchbase/var/lib/couchbase/logs
tech-blog | LOGBACK: No context given for c.q.l.core.rolling.SizeAndTimeBasedRollingPolicy#1908923184
tech-blog |
tech-blog | . ____ _ __ _ _
tech-blog | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
tech-blog | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
tech-blog | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
tech-blog | ' |____| .__|_| |_|_| |_\__, | / / / /
tech-blog | =========|_|==============|___/=/_/_/_/
tech-blog | :: Spring Boot :: (v2.2.4.RELEASE)
tech-blog |
couchbase-demo |
tech-blog | 02:07:25.243 [main] INFO com.tech.blog.TechBlogApplication - Starting TechBlogApplication v0.0.2-SNAPSHOT on bf6509f5200d with PID 1 (/opt/tech/techblog.jar started by root in /opt/tech)
tech-blog | 02:07:25.250 [main] DEBUG com.tech.blog.TechBlogApplication - Running with Spring Boot v2.2.4.RELEASE, Spring v5.2.3.RELEASE
tech-blog | 02:07:25.251 [main] INFO com.tech.blog.TechBlogApplication - No active profile set, falling back to default profiles: default
tech-blog | 02:07:28.543 [main] INFO o.a.catalina.core.StandardService - Starting service [Tomcat]
tech-blog | 02:07:28.544 [main] INFO o.a.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/9.0.30]
tech-blog | 02:07:28.683 [main] INFO o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext
tech-blog | 02:07:29.984 [cb-events] INFO com.couchbase.core - [com.couchbase.core][DnsSrvLookupFailedEvent][30ms] DNS SRV lookup failed (name not found), trying to bootstrap from given hostname directly.
tech-blog | 02:07:30.795 [cb-events] INFO com.couchbase.core - [com.couchbase.core][CoreCreatedEvent] {"clientVersion":"3.0.3","clientGitHash":"e55f7d43","coreVersion":"2.0.4","coreGitHash":"e55f7d43","userAgent":"couchbase-java/3.0.3 (Linux 4.19.76-linuxkit amd64; OpenJDK 64-Bit Server VM 1.8.0_121-b13)","maxNumRequestsInRetry":32768,"ioEnvironment":{"nativeIoEnabled":true,"eventLoopThreadCount":2,"eventLoopGroups":["EpollEventLoopGroup"]},"ioConfig":{"captureTraffic":[],"mutationTokensEnabled":true,"networkResolution":"auto","dnsSrvEnabled":true,"tcpKeepAlivesEnabled":true,"tcpKeepAliveTimeMs":60000,"configPollIntervalMs":2500,"kvCircuitBreakerConfig":"disabled","queryCircuitBreakerConfig":"disabled","viewCircuitBreakerConfig":"disabled","searchCircuitBreakerConfig":"disabled","analyticsCircuitBreakerConfig":"disabled","managerCircuitBreakerConfig":"disabled","numKvConnections":1,"maxHttpConnections":12,"idleHttpConnectionTimeoutMs":30000,"configIdleRedialTimeoutMs":300000},"compressionConfig":{"enabled":true,"minRatio":0.83,"minSize":32},"securityConfig":{"tlsEnabled":false,"nativeTlsEnabled":true,"hasTrustCertificates":false,"trustManagerFactory":null},"timeoutConfig":{"kvMs":10000000,"kvDurableMs":10000,"managementMs":75000,"queryMs":75000,"viewMs":75000,"searchMs":75000,"analyticsMs":75000,"connectMs":10000000,"disconnectMs":10000},"loggerConfig":{"customLogger":null,"fallbackToConsole":false,"disableSlf4j":false,"loggerName":"CouchbaseLogger","diagnosticContextEnabled":false},"orphanReporterConfig":{"emitIntervalMs":10000,"sampleSize":10,"queueLength":1024},"retryStrategy":"BestEffortRetryStrategy","requestTracer":"OwnedSupplier"} {"coreId":"0xce88bae700000001"}
tech-blog | 02:07:30.806 [cb-events] INFO com.couchbase.node - [com.couchbase.node][NodeConnectedEvent] Node connected {"coreId":"0xce88bae700000001","managerPort":"8091","remote":"localhost"}
tech-blog | 02:07:30.829 [cb-events] WARN com.couchbase.endpoint - [com.couchbase.endpoint][EndpointConnectionFailedEvent][271ms] Connect attempt 1 failed because of AnnotatedConnectException: finishConnect(..) failed: Connection refused: localhost/127.0.0.1:11210 {"circuitBreaker":"DISABLED","coreId":"0xce88bae700000001","remote":"localhost:11210","type":"KV"}
tech-blog | com.couchbase.client.core.deps.io.netty.channel.AbstractChannel$AnnotatedConnectException: finishConnect(..) failed: Connection refused: localhost/127.0.0.1:11210
tech-blog | Caused by: java.net.ConnectException: finishConnect(..) failed: Connection refused
tech-blog | at com.couchbase.client.core.deps.io.netty.channel.unix.Errors.throwConnectException(Errors.java:124)
tech-blog | at com.couchbase.client.core.deps.io.netty.channel.unix.Socket.finishConnect(Socket.java:243)
tech-blog | at com.couchbase.client.core.deps.io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.doFinishConnect(AbstractEpollChannel.java:672)
tech-blog | at com.couchbase.client.core.deps.io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.finishConnect(AbstractEpollChannel.java:649)
tech-blog | at com.couchbase.client.core.deps.io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.epollOutReady(AbstractEpollChannel.java:529)
tech-blog | at com.couchbase.client.core.deps.io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:465)
tech-blog | at com.couchbase.client.core.deps.io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:378)
tech-blog | at com.couchbase.client.core.deps.io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
tech-blog | at com.couchbase.client.core.deps.io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
tech-blog | at com.couchbase.client.core.deps.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
tech-blog | at java.lang.Thread.run(Thread.java:745)
Below is my docker-compose file.
services:
couchbase.lcl:
image: bentonam/couchbase-docker:latest
container_name: couchbase-demo
ports:
- "8091-8094:8091-8094"
- "11210:11210"
environment:
CLUSTER_USERNAME: Administrator
CLUSTER_PASSWORD: pass
CLUSTER_NAME: TECH_BLOG_CLUSTER
SERVICES: data,index,query,fts
CLUSTER_RAMSIZE: 500
BUCKET: user-profile
BUCKET_RAMSIZE: 300
NODE_INIT_INDEX_PATH: /opt/couchbase/var/lib/couchbase/indexes
networks:
- tech-blog-network
techblog.lcl:
image: docker-tech-blog:latest
restart: always
container_name: tech-blog
links:
- couchbase.lcl
environment:
COUCHBASE_HOST: couchbase.lcl
depends_on:
- couchbase.lcl
ports:
- "8123:8123"
networks:
- tech-blog-network
networks:
tech-blog-network:
driver: bridge
Can anyone please let me know is there any issue with my docker-compose file?
Below is my spring configuration file
server:
port: 8123
logging:
level:
org.springframework: ERROR
com.tech.blog: DEBUG
pattern:
console: "%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"
file: "%d %p %c{1.} [%t] %m%n"
file: /var/log/techblog.log
management:
endpoint:
health:
show-details: always
endpoints:
web:
exposure:
include: "*"
health:
defaults:
enabled: false
cb:
connectionTimeOut: 10000
kvTimeOut: 10000
hosts: localhost
cluster:
username: Administrator
password: pass
bucketname: user-profile
its not localhost when you are using docker container for each service.
change: hosts: localhost
to: hosts: couchbase.lcl

Docker-Compose Java Springboot and MySQL

I try to use docker-compose to containerize with starting MySQL server container first, and then start a Springboot Container to connect with the MySQL container.
But the Connection is fail(See full version in the terminal log below
web_1 | com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
How should I make changes to start my MySQL container first, then link it the Springboot Server to MySQL?
My terminal log
$ docker-compose up
Creating network "backend_default" with the default driver
Creating backend_db_1 ... done
Creating backend_web_1 ... done
Attaching to backend_db_1, backend_web_1
db_1 | 2020-03-15 05:59:09+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
db_1 | 2020-03-15 05:59:09+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db_1 | 2020-03-15 05:59:09+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
web_1 | Trying to connect to MySQL at db:3306...
db_1 | 2020-03-15 05:59:09+00:00 [Note] [Entrypoint]: Initializing database files
web_1 | /wrapper.sh: connect: Connection refused
web_1 | /wrapper.sh: line 2: /dev/tcp/db/3306: Connection refused
db_1 | 2020-03-15T05:59:09.686844Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
db_1 | 2020-03-15T05:59:09.686961Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.19) initializing of server in progress as process 43
db_1 | 2020-03-15T05:59:12.938749Z 5 [Warning] [MY-010453] [Server] root#localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
db_1 | 2020-03-15 05:59:16+00:00 [Note] [Entrypoint]: Database files initialized
db_1 | 2020-03-15 05:59:16+00:00 [Note] [Entrypoint]: Starting temporary server
db_1 | 2020-03-15T05:59:17.100779Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
db_1 | 2020-03-15T05:59:17.100921Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 93
db_1 | 2020-03-15T05:59:17.688885Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
db_1 | 2020-03-15T05:59:17.692200Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
db_1 | 2020-03-15T05:59:17.730154Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.19' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server - GPL.
db_1 | 2020-03-15 05:59:17+00:00 [Note] [Entrypoint]: Temporary server started.
db_1 | 2020-03-15T05:59:17.802956Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock'
db_1 | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
db_1 | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
web_1 | /wrapper.sh: connect: Connection refused
web_1 | /wrapper.sh: line 2: /dev/tcp/db/3306: Connection refused
web_1 | Trying to connect to MySQL at db:3306...
db_1 | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
db_1 | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
db_1 | 2020-03-15 05:59:24+00:00 [Note] [Entrypoint]: Creating database dog_of_the_dow_app
db_1 | 2020-03-15 05:59:24+00:00 [Note] [Entrypoint]: Creating user shihao
db_1 | 2020-03-15 05:59:24+00:00 [Note] [Entrypoint]: Giving user shihao access to schema dog_of_the_dow_app
db_1 |
db_1 | 2020-03-15 05:59:24+00:00 [Note] [Entrypoint]: Stopping temporary server
db_1 | 2020-03-15T05:59:24.460353Z 14 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.19).
db_1 | 2020-03-15T05:59:25.812000Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.19) MySQL Community Server - GPL.
db_1 | 2020-03-15 05:59:26+00:00 [Note] [Entrypoint]: Temporary server stopped
db_1 |
db_1 | 2020-03-15 05:59:26+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
db_1 |
db_1 | 2020-03-15T05:59:26.755391Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
db_1 | 2020-03-15T05:59:26.755538Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 1
db_1 | 2020-03-15T05:59:27.241304Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
db_1 | 2020-03-15T05:59:27.245423Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
db_1 | 2020-03-15T05:59:27.270535Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.19' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
db_1 | 2020-03-15T05:59:27.417150Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
web_1 | >> connected to MySQL database! <<
web_1 |
web_1 | . ____ _ __ _ _
web_1 | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
web_1 | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
web_1 | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
web_1 | ' |____| .__|_| |_|_| |_\__, | / / / /
web_1 | =========|_|==============|___/=/_/_/_/
web_1 | :: Spring Boot :: (v2.2.4.RELEASE)
web_1 |
web_1 | 2020-03-15 05:59:32.794 INFO 8 --- [ main] c.s.a.w.d.DogOfTheDowAppApplication : Starting DogOfTheDowAppApplication v0.0.1-SNAPSHOT on 754a319ebef1 with PID 8 (/app.jar started by root in /)
web_1 | 2020-03-15 05:59:32.811 INFO 8 --- [ main] c.s.a.w.d.DogOfTheDowAppApplication : The following profiles are active: containers
web_1 | 2020-03-15 05:59:34.732 INFO 8 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
web_1 | 2020-03-15 05:59:34.886 INFO 8 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 131ms. Found 2 JPA repository interfaces.
web_1 | 2020-03-15 05:59:35.721 INFO 8 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
web_1 | 2020-03-15 05:59:36.338 INFO 8 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
web_1 | 2020-03-15 05:59:36.375 INFO 8 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
web_1 | 2020-03-15 05:59:36.376 INFO 8 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.30]
web_1 | 2020-03-15 05:59:36.528 INFO 8 --- [ main] o.a.c.c.C.[.[.[/mobile-app-ws] : Initializing Spring embedded WebApplicationContext
web_1 | 2020-03-15 05:59:36.529 INFO 8 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3531 ms
web_1 | 2020-03-15 05:59:37.363 INFO 8 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
web_1 | 2020-03-15 05:59:37.588 INFO 8 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.4.10.Final}
web_1 | 2020-03-15 05:59:38.015 INFO 8 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
web_1 | 2020-03-15 05:59:38.325 INFO 8 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
web_1 | 2020-03-15 05:59:39.613 ERROR 8 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
web_1 |
web_1 | com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
web_1 |
web_1 | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
web_1 | at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.19.jar!/:8.0.19]
web_1 | at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.19.jar!/:8.0.19]
...
....
web_1 |
backend_web_1 exited with code 1
My Dockerfile
Download required images
and run the wrapper.sh
wrapper.sh will keep checking if the mysql container is successfully running
if so, than start the springboot, otherwise not
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ARG SH_FILE=src/main/resources/*.sh
COPY ${SH_FILE} wrapper.sh
RUN /bin/sh -c "apk add --no-cache bash"
RUN bash -c 'touch /app.jar'
RUN bash -c 'chmod +x /wrapper.sh'
ENTRYPOINT ["/bin/bash", "/wrapper.sh"]
My wrapper.sh file
keep checking mysql server
#!/usr/bin/env bash
while ! exec 6<>/dev/tcp/${DATABASE_HOST}/${DATABASE_PORT}; do
echo "Trying to connect to MySQL at ${DATABASE_HOST}:${DATABASE_PORT}..."
sleep 10
done
echo ">> connected to MySQL database! <<"
java -Djava.security.egd=file:/dev/./urandom -Dspring.profiles.active=containers -jar /app.jar
My docker-compose file
version: "2"
services:
db:
image: mysql:latest
environment:
- MYSQL_ROOT_PASSWORD=rootpassword
- MYSQL_DATABASE=example
- MYSQL_USER=shihao
- MYSQL_PASSWORD=shihao
ports:
- 3306:3306
web:
image: xli68/dog_of_the_dow:latest
depends_on:
- db
ports:
- 8080:8080
environment:
- DATABASE_HOST=db
- DATABASE_USER=shihao
- DATABASE_PASSWORD=shihao
- DATABASE_NAME=dog_of_the_dow_app
- DATABASE_PORT=3306

Initialization when running Junit Test case in Spring Boot

I'm writing test cases for service and util classes for my spring boot application. Following are snippets from the test cases
FooServiceImplTest.java
#RunWith(SpringRunner.class)
#SpringBootTest
public class FooServiceImplTest {
#Test
//test cases for FooServiceImplTest
}
BarUtilTest.java
#RunWith(SpringRunner.class)
#SpringBootTest
public class BarUtilTest {
#Test
//test cases for BarUtilTest
}
Now, when I run the test cases, I see something like the following in the console
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.0.RELEASE)
17:21:07.835 [main] INFO c.c.l.s.impl.FooServiceImplTest - Starting FooServiceImplTest on Users-MacBook-Pro.local with PID 8944 (started by user in /Users/user/Documents/my-project)
17:21:07.836 [main] DEBUG c.c.l.s.impl.FooServiceImplTest - Running with Spring Boot v2.1.0.RELEASE, Spring v5.1.2.RELEASE
17:21:07.836 [main] INFO c.c.l.s.impl.FooServiceImplTest - The following profiles are active: prod
17:21:10.828 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-2 - Starting...
17:21:10.890 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-2 - Start completed.
...
// runs test cases for FooServiceImplTest
17:21:33.643 [main] INFO c.c.l.s.impl.FooServiceImplTest - Started FooServiceImplTest in 40.898 seconds (JVM running for 102.231)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.0.RELEASE)
17:21:49.290 [main] INFO c.c.l.util.BarUtilTest - Starting BarUtilTest on Users-MacBook-Pro.local with PID 8944 (started by user in /Users/user/Documents/my-project)
17:21:49.290 [main] DEBUG c.c.l.util.BarUtilTest - Running with Spring Boot v2.1.0.RELEASE, Spring v5.1.2.RELEASE
17:21:49.290 [main] INFO c.c.l.util.BarUtilTest - The following profiles are active: prod
17:21:50.809 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-3 - Starting...
17:21:50.972 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-3 - Start completed.
...
// runs test cases for BarUtilTest
17:22:04.765 [main] INFO c.c.l.util.BarUtilTest - Started BarUtilTest in 30.635 seconds (JVM running for 133.353)
So it looks like for every test suite I write, everything is initialized again. That may be one of the reasons that it is taking a lot of time to run the test cases as I add more test suites. Is there anyway to initialize everything once and run all test cases in one go?

How to prevent Spring Tool Suite from adding extra data/details in the console on every compilation

I'm new to Java/Spring and whenever I compile and run a package or class in Spring Tool Suite, I will see the output, but STS will also included a bunch of other information that I'm really not concerned about. How can I make it so that STS only shows me the output and relevant errors and not all the extraneous info like the stuff below:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.5.RELEASE)
2018-10-01 20:43:06.780 INFO 74504 --- [ main] JDBCTest.CodeWarsAppApplication : Starting CodeWarsAppApplication on Johns-MacBook-Pro-3.local with PID 74504 (/Users/johnwolfe/Documents/workspace-sts-3.9.5.RELEASE/demo/CodeWarsApp/bin/main started by johnwolfe in /Users/johnwolfe/Documents/workspace-sts-3.9.5.RELEASE/demo/CodeWarsApp)
2018-10-01 20:43:06.785 INFO 74504 --- [ main] JDBCTest.CodeWarsAppApplication : No active profile set, falling back to default profiles: default
2018-10-01 20:43:06.840 INFO 74504 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#413d1baf: startup date [Mon Oct 01 20:43:06 CDT 2018]; root of context hierarchy
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils$1 (file:/Users/johnwolfe/.gradle/caches/modules-2/files-2.1/org.springframework/spring-core/5.0.9.RELEASE/9f9a828936d81afd49a603bda9cc1aed863a0d85/spring-core-5.0.9.RELEASE.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2018-10-01 20:43:07.409 INFO 74504 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-10-01 20:43:07.425 INFO 74504 --- [ main] JDBCTest.CodeWarsAppApplication : Started CodeWarsAppApplication in 0.99 seconds (JVM running for 1.436)
2018-10-01 20:43:07.429 INFO 74504 --- [ Thread-1] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#413d1baf: startup date [Mon Oct 01 20:43:06 CDT 2018]; root of context hierarchy
2018-10-01 20:43:07.431 INFO 74504 --- [ Thread-1] o.s.j.e.a.AnnotationMBeanExporter
Apparently you need to change the default logger threshold. This can be done in your application.properties or else directly to your logger config file if you are using any third party logging libraries.
The allowed levels are : ERROR, WARN, INFO, DEBUG, or TRACE.
For Spring Boot the defaults are :
ROOT :
logging.level.root=ERROR
Spring WEB :
logging.level.org.springframework.web: ERROR
In case you are using Hibernate :
logging.level.org.hibernate: ERROR
More info at Spring's Boot Logging Page

Categories