Error while running Springboot app in Kubernetes in Docket Desktop - spring-boot

I created a simple spring boot application and created a docker image. Tested the docker image on local (windows 10 professional) machine and it worked. Then I tried to run the image using kubectl run command, but it doesn't work.
Here are the details :
Environment - Windows 10 Professional, Docker Desktop, Java 8, Created Spring Boot app in Spring Tool Suite
Spring Boot project
application.properties has following entry
server.port=8085
The controller contains following
#RestController
public class TomcatController {
#GetMapping("/hello")
public Collection<String> sayHello() {
return IntStream.range(0, 10)
.mapToObj(i -> "Hello number " + i)
.collect(Collectors.toList());
}
}
Dockerfile contains following
FROM openjdk:8
ADD target/demowar1.jar demowar1.jar
EXPOSE 8085
ENTRYPOINT ["java" , "-jar" , "demowar1.jar"]
Used docker build command to create the image
docker build -t sudhirj8/demowar1 .
Ran the docker run command and verified it works
docker run --name demowar1 -p 8085:8085 sudhirj8/demowar1
In browser, used localhost:8085 and see proper output
Removed the running container
Ran following command to run in Kubernetes
kubectl run demowar1 --image sudhirj8/demowar1
Pod is created successfully
But when I run localhost:8085/hello browser, I get error
Unable to connect
Ran command kubectl logs demowar1 and see that tomcat started on port 8085 properly
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.5.1)
2021-06-11 23:52:15.037 INFO 1 --- [ main] com.example.demo.Demowar1Application : Starting Demowar1Application v0.0.1-SNAPSHOT using Java 1.8.0_292 on demowar1-pod with PID 1 (/demowar1.jar started by root in /)
2021-06-11 23:52:15.039 INFO 1 --- [ main] com.example.demo.Demowar1Application : No active profile set, falling back to default profiles: default
2021-06-11 23:52:15.937 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8085 (http)
2021-06-11 23:52:15.948 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-06-11 23:52:15.948 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.46]
2021-06-11 23:52:15.999 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-06-11 23:52:15.999 INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 915 ms
2021-06-11 23:52:16.491 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8085 (http) with context path ''
2021-06-11 23:52:16.499 INFO 1 --- [ main] com.example.demo.Demowar1Application : Started Demowar1Application in 1.83 seconds (JVM running for 2.22)

The Pod here can't be reached from your machine until it's exposed. You can do that by creating a service which directs your requests to the pods.
https://kubernetes.io/docs/concepts/services-networking/service/
Alternatively, If you want to test only without exposing your app, you can do port-forward from your machine to pods, like below
kubectl port-forward pods/demowar1 8085:8085
and then do localhost:8085 on your machine.
Documentation for the same -> https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/

Related

Not able to curl an http rest api through a k8s service

I have following deployments and service but still not able to access the service on my Windows machine with minikube installed on it.
# kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
helloworld-dep 3/3 3 3 9h
# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
greet-api-demo 1/1 Running 2 (23m ago) 6d9h 172.17.0.5 minikube <none> <none>
helloworld-dep-f8586dd84-28dxg 1/1 Running 1 (23m ago) 9h 172.17.0.6 minikube <none> <none>
helloworld-dep-f8586dd84-p4pg9 1/1 Running 1 (23m ago) 9h 172.17.0.7 minikube <none> <none>
helloworld-dep-f8586dd84-tgmcj 1/1 Running 1 (23m ago) 9h 172.17.0.8 minikube <none> <none>
# kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
helloworld-service NodePort 10.96.44.199 <none> 80:30008/TCP 4m1s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 191d
# kubectl logs helloworld-dep-f8586dd84-28dxg
Setting Active Processor Count to 8
Calculating JVM memory based on 11276448K available memory
For more information on this calculation, see https://paketo.io/docs/reference/java-reference/#memory-calculator
Calculated JVM Memory Configuration: -XX:MaxDirectMemorySize=10M -Xmx10889346K -XX:MaxMetaspaceSize=79901K -XX:ReservedCodeCacheSize=240M -Xss1M (Total Memory: 11276448K, Thread Count: 50, Loaded Class Count: 11693, Headroom: 0%)
Enabling Java Native Memory Tracking
Adding 124 container CA certificates to JVM truststore
Spring Cloud Bindings Enabled
Picked up JAVA_TOOL_OPTIONS: -Djava.security.properties=/layers/paketo-buildpacks_bellsoft-liberica/java-security-properties/java-security.properties -XX:+ExitOnOutOfMemoryError -XX:ActiveProcessorCount=8 -XX:MaxDirectMemorySize=10M -Xmx10889346K -XX:MaxMetaspaceSize=79901K -XX:ReservedCodeCacheSize=240M -Xss1M -XX:+UnlockDiagnosticVMOptions -XX:NativeMemoryTracking=summary -XX:+PrintNMTStatistics -Dorg.springframework.cloud.bindings.boot.enable=true
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.0.0)
2022-12-23T03:38:53.397Z INFO 1 --- [ main] com.playground.k8s.K8sDemoApplication : Starting K8sDemoApplication using Java 17.0.5 with PID 1 (/workspace/BOOT-INF/classes started by cnb in /workspace)
2022-12-23T03:38:53.403Z INFO 1 --- [ main] com.playground.k8s.K8sDemoApplication : No active profile set, falling back to 1 default profile: "default"
2022-12-23T03:39:14.389Z INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-12-23T03:39:14.648Z INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-12-23T03:39:14.650Z INFO 1 --- [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.1]
2022-12-23T03:39:15.883Z INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-12-23T03:39:15.888Z INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 21396 ms
2022-12-23T03:39:19.693Z INFO 1 --- [ main] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page template: index
2022-12-23T03:39:23.699Z INFO 1 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 1 endpoint(s) beneath base path '/actuator'
2022-12-23T03:39:25.262Z INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-12-23T03:39:25.397Z INFO 1 --- [ main] com.playground.k8s.K8sDemoApplication : Started K8sDemoApplication in 35.178 seconds (process running for 38.144)
Tried minikube ip, clusterip and node ip but none of them worked !
# curl http://192.168.49.2:30008/actuator
curl: (28) Failed to connect to 192.168.49.2 port 30008 after 21061 ms: Timed out
# curl http://10.96.44.199:30008/actuator
curl: (28) Failed to connect to 10.96.44.199 port 30008 after 21034 ms: Timed out
# curl http://172.17.0.6:30008/actuator
curl: (28) Failed to connect to 172.17.0.6 port 30008 after 21052 ms: Timed out
Not sure from where you are truing to hit the curl but you will be only able to curl those IP if truing inside of Kubernetes cluster.
Cluster IP is internal, you will be able to access it internal or internal services can use it to access it.
You can run one container extra to test this
kubectl run -it --rm --image=curlimages/curl curly -- sh
after command try curl <clusterIP> or curl helloworld-service
If you want to try from outside from Host machine you can check URL with
minikube service helloworld-service --url
try once curl localhost:30008/actuator
For node port you can get minikube IP with command
minikube ip
curl MinikubeIP:30008

SpringBoot3 + POI + Log4j GraalVm Native Image Runtime Error: Defining hidden classes at runtime is not supported

In the SpringBoot3 application built by Graalvm Native Image, I use Apache Poi to depend on log4j. The construction is successful, but the following errors occur at running. How can I configure it to avoid this error?
I tested in Spring Boot 2.7.1 + Spring Native, there is no problem.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.0.0)
2022-12-06T11:53:05.855+08:00 INFO 18532 --- [ restartedMain] com.example.dataserver.Application : Starting AOT-processed Application using Java 17.0.5 with PID 18532 (D:\work-ide\IDEA\data-server\target\data-server.exe started by westinyang in D:\work-ide\IDEA\data-server\target)
2022-12-06T11:53:05.855+08:00 INFO 18532 --- [ restartedMain] com.example.dataserver.Application : No active profile set, falling back to 1 default profile: "default"
2022-12-06T11:53:05.855+08:00 INFO 18532 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2022-12-06T11:53:05.855+08:00 INFO 18532 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2022-12-06T11:53:05.889+08:00 INFO 18532 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-12-06T11:53:05.889+08:00 INFO 18532 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-12-06T11:53:05.889+08:00 INFO 18532 --- [ restartedMain] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.1]
2022-12-06T11:53:05.897+08:00 INFO 18532 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-12-06T11:53:05.897+08:00 INFO 18532 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 41 ms
2022-12-06T11:53:05.920+08:00 INFO 18532 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-12-06T11:53:05.921+08:00 INFO 18532 --- [ restartedMain] com.example.dataserver.Application : Started Application in 0.072 seconds (process running for 0.078)
ERROR StatusLogger Unable to load services for service class org.apache.logging.log4j.spi.Provider
java.lang.InternalError: com.oracle.svm.core.jdk.UnsupportedFeatureError: Defining hidden classes at runtime is not supported.
at java.base#17.0.5/java.lang.invoke.InnerClassLambdaMetafactory.generateInnerClass(InnerClassLambdaMetafactory.java:413)
at java.base#17.0.5/java.lang.invoke.InnerClassLambdaMetafactory.spinInnerClass(InnerClassLambdaMetafactory.java:315)
at java.base#17.0.5/java.lang.invoke.InnerClassLambdaMetafactory.buildCallSite(InnerClassLambdaMetafactory.java:228)
at java.base#17.0.5/java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:341)
at org.apache.logging.log4j.util.ServiceLoaderUtil.loadClassloaderServices(ServiceLoaderUtil.java:93)
at org.apache.logging.log4j.util.ServiceLoaderUtil.loadServices(ServiceLoaderUtil.java:74)
at org.apache.logging.log4j.util.ServiceLoaderUtil.loadServices(ServiceLoaderUtil.java:68)
at org.apache.logging.log4j.util.ProviderUtil.<init>(ProviderUtil.java:67)
at org.apache.logging.log4j.util.ProviderUtil.lazyInit(ProviderUtil.java:145)
at org.apache.logging.log4j.util.ProviderUtil.hasProviders(ProviderUtil.java:129)
at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:90)
at org.apache.poi.util.IOUtils.<clinit>(IOUtils.java:43)
at org.apache.poi.poifs.filesystem.FileMagic.valueOf(FileMagic.java:177)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:309)
at cn.hutool.poi.excel.WorkbookUtil.createBook(WorkbookUtil.java:120)
at cn.hutool.poi.excel.WorkbookUtil.createBook(WorkbookUtil.java:70)
at cn.hutool.poi.excel.ExcelReader.<init>(ExcelReader.java:71)
at cn.hutool.poi.excel.ExcelReader.<init>(ExcelReader.java:50)
at cn.hutool.poi.excel.ExcelUtil.getReader(ExcelUtil.java:151)
at cn.hutool.poi.excel.ExcelUtil.getReader(ExcelUtil.java:127)
at com.example.dataserver.AppRunner.run(AppRunner.java:23)
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:758)
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:748)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at com.example.dataserver.Application.main(Application.java:13)
at java.base#17.0.5/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:775)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.windows.WindowsPlatformThreads.osThreadStartRoutine(WindowsPlatformThreads.java:178)
Caused by: com.oracle.svm.core.jdk.UnsupportedFeatureError: Defining hidden classes at runtime is not supported.
at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:89)
at java.base#17.0.5/java.lang.ClassLoader.defineClass0(ClassLoader.java:338)
at java.base#17.0.5/java.lang.System$2.defineClass(System.java:2307)
at java.base#17.0.5/java.lang.invoke.MethodHandles$Lookup$ClassDefiner.defineClass(MethodHandles.java:2439)
at java.base#17.0.5/java.lang.invoke.MethodHandles$Lookup$ClassDefiner.defineClassAsLookup(MethodHandles.java:2420)
at java.base#17.0.5/java.lang.invoke.MethodHandles$Lookup.defineHiddenClass(MethodHandles.java:2127)
at java.base#17.0.5/java.lang.invoke.InnerClassLambdaMetafactory.generateInnerClass(InnerClassLambdaMetafactory.java:407)
... 28 more
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
2022-12-06T11:53:05.981+08:00 INFO 18532 --- [ restartedMain] com.example.dataserver.AppRunner : 3
2022-12-06T11:53:05.981+08:00 INFO 18532 --- [ restartedMain] com.example.dataserver.AppRunner : Service running on 127.0.0.1:8080
pom.xml dependencies
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.10</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.3</version>
</dependency>
I tried some solutions, but there is no effect yet,I joined the native-image parameter --initialize-at-run-time=org.apache.logging.log4j.spi.Provider
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<configuration>
<buildArgs>
<arg>--no-fallback</arg>
<arg>--initialize-at-run-time=org.apache.logging.log4j.spi.Provider</arg>
<arg>-H:+AddAllCharsets</arg>
</buildArgs>
</configuration>
</plugin>

org.apache.tomcat.util.modeler.Registry.disableRegistry() Error while running SpringBoot

I am new to SpringBoot and when am trying to run the Application i have encountered this problem in Tomcat.
Do we have to have any specific tomcat verison only to run Spring boot.
Following are the Configurations in my system:
Java 17
Apache Tomcat version 8.036
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.5)
2022-11-08 16:40:04.056 INFO 2848 --- [ main] c.g.s.SpringBootSecurityApplication : Starting SpringBootSecurityApplication using Java 17.0.5 on DESKTOP-3JTUENI with PID 2848 (C:\Users\User.DESKTOP-3JTUENI\Downloads\Spring Boot Security\Spring Boot Security\Final Project\spring-boot-security\spring-boot-security\target\classes started by User in C:\Users\User.DESKTOP-3JTUENI\Downloads\Spring Boot Security\Spring Boot Security\Final Project\spring-boot-security\spring-boot-security)
2022-11-08 16:40:04.093 INFO 2848 --- [ main] c.g.s.SpringBootSecurityApplication : No active profile set, falling back to default profiles: default
2022-11-08 16:40:10.257 INFO 2848 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-11-08 16:40:10.623 INFO 2848 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 300 ms. Found 3 JPA repository interfaces.
2022-11-08 16:40:13.193 WARN 2848 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is java.lang.NoSuchMethodError: 'void org.apache.tomcat.util.modeler.Registry.disableRegistry()'
2022-11-08 16:40:13.260 INFO 2848 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-11-08 16:40:13.341 ERROR 2848 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:183)
The following method did not exist:
'void org.apache.tomcat.util.modeler.Registry.disableRegistry()'
The method's class, org.apache.tomcat.util.modeler.Registry, is available from the following locations:
jar:file:/C:/Users/User.DESKTOP-3JTUENI/Downloads/apache-tomcat-8.5.82/apache-tomcat-8.0.36/lib/tomcat-coyote.jar!/org/apache/tomcat/util/modeler/Registry.class
jar:file:/C:/Users/User.DESKTOP-3JTUENI/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.45/tomcat-embed-core-9.0.45.jar!/org/apache/tomcat/util/modeler/Registry.class
The class hierarchy was loaded from the following locations:
org.apache.tomcat.util.modeler.Registry: file:/C:/Users/User.DESKTOP-3JTUENI/Downloads/apache-tomcat-8.5.82/apache-tomcat-8.0.36/lib/tomcat-coyote.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.apache.tomcat.util.modeler.Registry
In pom.xml gave this dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
Can anyone let me know if we have to have any specific version of tomcat / Springboot or any other solution for this.

Getting error while trying to runa n maven based simple springboot project

I was trying to run the springboot project at port 8082. But it is failing again and again. Please give me a feasible solution.
Full Stacktrace:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.2.RELEASE)
2019-12-26 18:02:23.947 INFO 3680 --- [ restartedMain] c.i.s.w.s.SpringBootFirstWebApplication : Starting SpringBootFirstWebApplication on DESKTOP-BK9RRM4 with PID 3680 (C:\Users\zunayeed\springboot-workspace01\spring-boot-first-web-application\spring-boot-first-web-application\target\classes started by zunayeed in C:\Users\zunayeed\springboot-workspace01\spring-boot-first-web-application\spring-boot-first-web-application)
2019-12-26 18:02:23.953 INFO 3680 --- [ restartedMain] c.i.s.w.s.SpringBootFirstWebApplication : No active profile set, falling back to default profiles: default
2019-12-26 18:02:24.294 INFO 3680 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2019-12-26 18:02:24.295 INFO 3680 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2019-12-26 18:02:29.465 INFO 3680 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8082 (http)
2019-12-26 18:02:29.514 INFO 3680 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-12-26 18:02:29.515 INFO 3680 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.29]
2019-12-26 18:02:29.926 INFO 3680 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-12-26 18:02:29.927 DEBUG 3680 --- [ restartedMain] o.s.web.context.ContextLoader : Published root WebApplicationContext as ServletContext attribute with name [org.springframework.web.context.WebApplicationContext.ROOT]
2019-12-26 18:02:29.927 INFO 3680 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 5628 ms
2019-12-26 18:02:30.726 INFO 3680 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-12-26 18:02:30.744 DEBUG 3680 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : ControllerAdvice beans: 0 #ModelAttribute, 0 #InitBinder, 1 RequestBodyAdvice, 1 ResponseBodyAdvice
2019-12-26 18:02:31.039 DEBUG 3680 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : 2 mappings in 'requestMappingHandlerMapping'
2019-12-26 18:02:31.130 DEBUG 3680 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Patterns [/webjars/**, /**] in 'resourceHandlerMapping'
2019-12-26 18:02:31.165 DEBUG 3680 --- [ restartedMain] .m.m.a.ExceptionHandlerExceptionResolver : ControllerAdvice beans: 0 #ExceptionHandler, 1 ResponseBodyAdvice
2019-12-26 18:02:31.345 WARN 3680 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : Unable to start LiveReload server
2019-12-26 18:02:31.811 INFO 3680 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2019-12-26 18:02:31.830 INFO 3680 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-12-26 18:02:31.832 ERROR 3680 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Web server failed to start. Port 8082 was already in use.
Action:
Identify and stop the process that's listening on port 8082 or configure this application to listen on another port.
2019-12-26 18:02:31.837 INFO 3680 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
Description:
Web server failed to start. Port 8082 was already in use.
Action:
Identify and stop the process that's listening on port 8082 or configure this application to listen on another port.
Possible causes:
Either you have already been running the application
Or another application is running in the same port
Solutions:
Configure the application to listen on another port(ex: 8081)
If you are using applcation.properties,
server.port=8081
If you are using application.yml
server:
port: 8081
Identify and stop the process that's listening on a port(8082)
window
ubuntu
mac
and restart your application
If you are using cmd or git bash , use the command :
netstat -ano
or further fine grain query :
nestat -ano | grep {port addr}
(note : grep only works in linux or gitbash , use findstr for cmd)
to identiy all the PID s that are currently running , which uses the particular port address that you want to use in your application. If the PIDs are not relevant , you could kill the PIDs using the command kill -9 {pid}. After that you could start your application in the same port.
Another easy approach is to use another port address which is not used by any other application. Just set the property server.port=8086 in your application.properties, or pass it as an argument when you start the application.

Starting Spring Cloud Config Server on Docker - InvalidRemoteException: Invalid remote: origin

I am trying to start a Spring Cloud Config Server on a Docker container and I am getting Invalid Remote exception. Reading the logs it seems that the Docker container doesn't have access to the Volume but I am not sure. I am using CentOs. any suggestion will be appreciatted.
Dockerfile
FROM openjdk:8-jdk-alpine
MAINTAINER jimis.drpc#gmail.com
COPY files/config-server-0.0.1-SNAPSHOT.jar /opt/spring-cloud/lib/
ENV SPRING_APPLICATION_JSON='{"spring": {"cloud": {"config": {"server": {"git": {"uri": "/var/lib/spring-cloud/config-repo", "clone-on-start": true}}}}}}'
ENTRYPOINT ["/usr/bin/java"]
CMD ["-jar", "/opt/spring-cloud/lib/config-server-0.0.1-SNAPSHOT.jar"]
VOLUME /var/lib/spring-cloud/config-repo
EXPOSE 8888
Spring Boot application.properties
server.port=8888
management.security.enabled=true
spring.autoconfigure.exclude=org.springframawork.boot.autoconfigure.SecurityAutoConfiguration
logs:
test]$ docker build --no-cache --file=Dockerfile --tag=config-server:latest --rm=true .
Sending build context to Docker daemon 30.3MB
Step 1/8 : FROM openjdk:8-jdk-alpine
---> 88d1c219f815
Step 2/8 : MAINTAINER jimis.drpc#gmail.com
---> Running in a204b40b9f04
Removing intermediate container a204b40b9f04
---> 456dacbfaefa
Step 3/8 : COPY files/config-server-0.0.1-SNAPSHOT.jar /opt/spring-cloud/lib/
---> 55d1d05d4999
Step 4/8 : ENV SPRING_APPLICATION_JSON='{"spring": {"cloud": {"config": {"server": {"git": {"uri": "/var/lib/spring-cloud/config-repo", "clone-on-start": true}}}}}}'
---> Running in 5036de819188
Removing intermediate container 5036de819188
---> dfecf1c03d37
Step 5/8 : ENTRYPOINT ["/usr/bin/java"]
---> Running in bfbbe5d1ec20
Removing intermediate container bfbbe5d1ec20
---> 9395dc9a8c81
Step 6/8 : CMD ["-jar", "/opt/spring-cloud/lib/config-server-0.0.1-SNAPSHOT.jar"]
---> Running in 0f5bc5285e8b
Removing intermediate container 0f5bc5285e8b
---> fc8e287837e7
Step 7/8 : VOLUME /var/lib/spring-cloud/config-repo
---> Running in 9125b1dcd48e
Removing intermediate container 9125b1dcd48e
---> 780c5215f875
Step 8/8 : EXPOSE 8888
---> Running in 7e752e7e84be
Removing intermediate container 7e752e7e84be
---> 8a664539c179
Successfully built 8a664539c179
Successfully tagged config-server:latest
[jimis#bv-vpc-1097 test]$ docker volume create --name=spring-cloud-config-repo
spring-cloud-config-repo
[jimis#bv-vpc-1097 test]$ docker run --name=config-server --publish=8888:8888 --volume=spring-cloud-config-repo:/var/lib/spring-cloud/config-repo config-server:latest
2019-04-11 16:22:17.683 INFO 1 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$9b802ec4] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.3.RELEASE)
2019-04-11 16:22:17.983 INFO 1 --- [ main] c.m.c.ConfigServerApplication : No active profile set, falling back to default profiles: default
2019-04-11 16:22:19.548 INFO 1 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=11be5ef3-61b1-3539-a246-b6326ba4f12c
2019-04-11 16:22:19.631 INFO 1 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$9b802ec4] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-04-11 16:22:20.199 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8888 (http)
2019-04-11 16:22:20.250 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-04-11 16:22:20.251 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.16]
2019-04-11 16:22:20.269 INFO 1 --- [ main] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/lib/jvm/java-1.8-openjdk/jre/lib/amd64/server:/usr/lib/jvm/java-1.8-openjdk/jre/lib/amd64:/usr/lib/jvm/java-1.8-openjdk/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
2019-04-11 16:22:20.561 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-04-11 16:22:20.561 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2551 ms
2019-04-11 16:22:21.652 WARN 1 --- [ main] .c.s.e.MultipleJGitEnvironmentRepository : Error occured cloning to base directory.
org.eclipse.jgit.api.errors.InvalidRemoteException: Invalid remote: origin
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:251) ~[org.eclipse.jgit-5.1.3.201810200350-r.jar!/:5.1.3.201810200350-r]
at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:306) ~[org.eclipse.jgit-5.1.3.201810200350-r.jar!/:5.1.3.201810200350-r]
at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:200) ~[org.eclipse.jgit-5.1.3.201810200350-r.jar!/:5.1.3.201810200350-r]
at org.springframework.cloud.config.server.environment.JGitEnvironmentRepository.cloneToBasedir(JGitEnvironmentRepository.java:589) [spring-cloud-config-server-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]

Resources