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>
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
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?
Using Apache Tomcat/8.5.24, running a Spring Boot application.
When we use the tomcat manager page and click "Reload" on our web-app, the app is not reloaded. catalina.out says that the context has been reloaded, but Spring does not fire and our endpoints don't respond. In order to get a real reload, we have to completely un-deploy the web app and re-deploy from scratch, which is less than ideal.
When I first deploy the app, I get the familiar
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.4.2.RELEASE)
Splash screen and all the associated controller bindings and bean creation logs. However, when I click "reload", I get this
23-Jan-2018 15:13:17.235 INFO [https-jsse-nio-8443-exec-10] org.apache.catalina.core.StandardContext.reload Reloading Context with name [/myapp] has started
23-Jan-2018 15:13:17.237 INFO [https-jsse-nio-8443-exec-10] org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext.doClose Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#283650df: startup date [Tue Jan 23 15:11:39 UTC 2018]; root of context hierarchy
23-Jan-2018 15:13:17.246 INFO [https-jsse-nio-8443-exec-10] org.springframework.context.support.DefaultLifecycleProcessor.stop Stopping beans in phase 2147483647
23-Jan-2018 15:13:17.247 INFO [https-jsse-nio-8443-exec-10] org.springframework.jmx.export.annotation.AnnotationMBeanExporter.destroy
Unregistering JMX-exposed beans on shutdown
System is shutting down
23-Jan-2018 15:13:17.428 INFO [https-jsse-nio-8443-exec-10] org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.shutdown Shutting down ExecutorService 'getAsyncExecutor'
23-Jan-2018 15:13:17.542 INFO [https-jsse-nio-8443-exec-10] org.apache.catalina.core.StandardContext.reload Reloading Context with name [/myapp] is completed
And that's it.
We are using external jars, defined in a context.xml file as follows:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/myapp" docBase="/myapp" reloadable="true">
<Resources>
<!-- Load the configuration files -->
<!-- Location of external log4j2 configuration file -->
<PreResources className="org.apache.catalina.webresources.DirResourceSet"
base="/mycompany/libs/config/"
webAppMount="/WEB-INF/classes" />
<!-- Location of the JARs -->
<JarResources className="org.apache.catalina.webresources.DirResourceSet"
base="/mycompany/libs/application_core/"
webAppMount="/WEB-INF/lib" />
<JarResources className="org.apache.catalina.webresources.DirResourceSet"
base="/mycompany/libs/application_supplemental/"
webAppMount="/WEB-INF/lib" />
<JarResources className="org.apache.catalina.webresources.DirResourceSet"
base="/mycompany/libs/third_party/"
webAppMount="/WEB-INF/lib" />
</Resources>
</Context>
Before we moved to this structure, this wasn't an issue so I assume it has something to do with this configuration but I'm not extremely familiar with all things tomcat and am not sure where to even look.
I'm trying to provide some custom logging levels to the default logback configuration, but it seems my configuration file is being ignored. I though Boot may skip it for whatever reason but if I make the file not valid (remove / of self-closing tag for example) I got an exception about not being able to parse it - so it is being picked up.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- Spring boot base -->
<include resource="org/springframework/boot/logging/logback/base.xml" />
<logger name="com.wedgetail" level="WARN" />
<logger name="nv" level="WARN" />
<logger name="StatsLogger" level="WARN" />
</configuration>
So for testing purposes (as my loggers are may be wrongly spelled or whatever) I included:
<logger name="org.springframework" level="ERROR" />
When the application comes up I still see spring logging on info level:
2014-08-22 14:28:34.756 WARN 5444 --- [on(3)-127.0.0.1] o.s.b.l.LoggingApplicationListener : Logging environment value '-Djava.util.logging.config.file="C:\Documents and Settings\zykajan\.IntelliJIdea13\system\tomcat\Unnamed_cnc-parent_2\conf\logging.properties"' cannot be opened and will be ignored
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.1.5.RELEASE)
2014-08-22 14:28:34.881 INFO 5444 --- [on(3)-127.0.0.1] o.s.boot.SpringApplication : Starting application on prgdwm395059 with PID 5444 (C:\workspace\command-and-control\webapp\target\cnc-webapp-UNVERSIONED-SNAPSHOT\WEB-INF\lib\spring-boot-1.1.5.RELEASE.jar started by zykajan in C:\Apps\Apache\jakarta\apache-tomcat-7.0.55\bin)
2014-08-22 14:28:34.928 INFO 5444 --- [on(3)-127.0.0.1] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#5dd439: startup date [Fri Aug 22 14:28:34 CEST 2014]; root of context hierarchy
I wonder whether the first line should ring bells unfortunatelly it doesn't in my case :)
2014-08-22 14:28:34.756 WARN 5444 --- [on(3)-127.0.0.1] o.s.b.l.LoggingApplicationListener : Logging environment value '-Djava.util.logging.config.file="C:\Documents and Settings\zykajan\.IntelliJIdea13\system\tomcat\Unnamed_cnc-parent_2\conf\logging.properties"' cannot be opened and will be ignored
As usual, any tips much appreciated.
Upgrade to Spring Boot 1.1.6. for a fix of this issue.