Can't override server port in jenkins - spring-boot

in windows batch command
mvn spring-boot:run -Dspring-boot.run.arguments=--server.port=8085
doesn't work
the console outputs:
main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8085 (https) with context path ''
2019-05-20 14:05:45.622 INFO 3144 --- [ main] g.s.i.InternalPortalApplication : Started InternalPortalApplication in 14.031 seconds (JVM running for 28.877)

Related

Could not reach the docker container web application even it run successfully

I wrote a simple backend application by spring boot and kotlin, here you can see the full settings https://github.com/lifeodyssey/demo
this bug performed as
I can start and access the application by ./gradlew bootRun
I can start and access the application by java -jar demo.jar
But I could not access the application when I try to start it in a container, even I can see a successful log by docker logs containerID. The log is given below
2022-11-12 15:50:33.017 INFO 1 --- [ main] com.example.demo.DemoApplicationKt : Starting DemoApplicationKt using Java 11.0.16 on eeb1dfe09e6a with PID 1 (/Demo-0.0.1.jar started by root in /)
2022-11-12 15:50:33.029 INFO 1 --- [ main] com.example.demo.DemoApplicationKt : No active profile set, falling back to 1 default profile: "default"
2022-11-12 15:50:34.315 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode
2022-11-12 15:50:34.320 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data MongoDB repositories in DEFAULT mode.
2022-11-12 15:50:34.346 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 15 ms. Found 0 MongoDB repository interfaces.
2022-11-12 15:50:35.564 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8000 (http)
2022-11-12 15:50:35.595 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-11-12 15:50:35.596 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.68]
2022-11-12 15:50:35.787 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-11-12 15:50:35.788 INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2628 ms
2022-11-12 15:50:38.155 WARN 1 --- [ main] o.s.b.a.m.MustacheAutoConfiguration : Cannot find template location: classpath:/templates/ (please add some templates, check your Mustache configuration, or set spring.mustache.check-template-location=false)
2022-11-12 15:50:38.346 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8000 (http) with context path ''
2022-11-12 15:50:38.412 INFO 1 --- [ main] com.example.demo.DemoApplicationKt : Started DemoApplicationKt in 6.588 seconds (JVM running for 7.745)
And here is the Dockerfile
FROM openjdk:11
COPY /build/libs/demo-0.0.1-SNAPSHOT.jar Demo-0.0.1.jar
EXPOSE 8000
ENTRYPOINT ["java","-jar","/Demo-0.0.1.jar"]
Here is the commmand I used to build image and run container
docker build -t demo .
docker run -dp 8000:8000 demo:latest
I could not find where is the problem. Can you help me with it ?
Update
Thanks for the comments below, here is what showed when I access localhost
This site can’t be reached localhost refused to connect.
Try:
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED
I have tried change -dp 8000 to -d -p 8000, but nothing changed.
Try to connect to it using 127.0.0.1:8000 instead of localhost:8000, maybe localhost is not resolving to 127.0.0.1.
If not try a different port and/or browser. Finally your firewall might be blocking your server so check that.
I finally found the issue.
I installed two application two run my docker. One is colima, another is Docker Desktop.
I guess the problem is that docker do not know which one is the "localhost".
This problem fixed after I uninstall docker desktop and link docker to colima.

Unable to call Spring Boot API inside Ubuntu WSL2 at localhost:8080 using Postman

I am having trouble calling and posting to an API build with Spring Boot inside a WSL2 Ubuntu environment. I can run the project and it gets initialized at port 8080 as shown in the logs:
:: Spring Boot :: (v2.7.4)
2022-10-14 16:18:11.033 INFO 32139 --- [ main] com.example.demo3.Demo3Application : Starting Demo3Application using Java 17.0.4 on LCE50469 with PID 32139 (/home/joschenk/ModelAPI/target/classes started by joschenk in /home/joschenk/ModelAPI)
2022-10-14 16:18:11.036 INFO 32139 --- [ main] com.example.demo3.Demo3Application : No active profile set, falling back to 1 default profile: "default"
2022-10-14 16:18:11.716 INFO 32139 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-10-14 16:18:11.722 INFO 32139 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-10-14 16:18:11.722 INFO 32139 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.65]
2022-10-14 16:18:11.779 INFO 32139 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-10-14 16:18:11.779 INFO 32139 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 703 ms
2022-10-14 16:18:12.005 INFO 32139 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-10-14 16:18:12.012 INFO 32139 --- [ main] com.example.demo3.Demo3Application : Started Demo3Application in 1.227 seconds (JVM running for 1.655)
When now trying to Post to the API using Postman with
POST http://localhost:8080/api/v1/model
I am getting the following response:
Error: connect ECONNREFUSED 127.0.0.1:8080
Request Headers
Content-Type: application/json
User-Agent: PostmanRuntime/7.29.2
Accept: */*
Postman-Token: 846f27f6-f2e6-4d0f-9554-3fdb3f352bc9
Host: localhost:8080
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Can someone help here? Thanks!
I solved the issue by running a wsl2 kernel update inside the Windows Powershell. I then rebooted everything and now it works.
wsl --update
wsl --shutdown

Vaadin 23 Flow - Spring Boot - Live Reload not working

I recently updated my Vaadin Flow Project to the newest Version 23.0.1.
It all did great, but the LiveReload (detecting Java-FileChanges) doesnt work at all (Its detecting only CSS changes).
I created a new Spring Boot Vaadin 23 Project with Spring-Initializr to check if it's the same problem. I followed the LiveReload Section in the official Vaadin Docs, but it does'nt work at all... :(
My Console shows no errors at all..
Does someone have a similar Problem?
Console Output:
2022-03-21 12:28:33.379 INFO 16300 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
[.....]
2022-03-21 12:28:33.814 INFO 16300 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8081 (http) with context path ''
2022-03-21 12:28:33.827 INFO 16300 --- [ restartedMain] n.b.p.s.PlatonStartupApplicationListener : Initialize Application
2022-03-21 12:28:33.828 INFO 16300 --- [ restartedMain] n.b.p.s.PlatonStartupApplicationListener : Load global catalog.
2022-03-21 12:28:33.987 INFO 16300 --- [nio-8081-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-03-21 12:28:33.988 INFO 16300 --- [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2022-03-21 12:28:33.992 INFO 16300 --- [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 2 ms
2022-03-21 12:28:38.306 INFO 16300 --- [v-server-output] c.v.b.devserver.DevServerOutputTracker : [build-status] : Compiled.
←[38;5;35m
----------------- Frontend compiled successfully. -----------------
←[0m2022-03-21 12:28:38.313 INFO 16300 --- [onPool-worker-3] c.v.b.devserver.AbstractDevServerRunner : Started Webpack. Time: 9897ms
2022-03-21 12:28:38.382 INFO 16300 --- [v-server-output] c.v.b.devserver.DevServerOutputTracker : No issues found.

Not able to access springboot application running inside a container on MacOs

I have a springboot application running inside a container on macOS Catalina. Logs show that the application is up and running inside the container however I cannot reach it from browser.
I have tried accessing it using :
localhost:8081/
0.0.0.0:8081/ and
127.0.0.1/8081/
But nothing helped. I have also added server.address=0.0.0.0 to my application.properties file but that didn't help either.
This is how I run my container:
docker run --name spring_boot_docker -it --link mysql-dev-server:db -p 8081:8081 demo_docker_kubernetes
Logs show application is running fine:
2020-04-12 00:21:40.149 INFO 1 --- [ main]
o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService
'applicationTaskExecutor'
2020-04-12 00:21:40.632 INFO 1 --- [ main]
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8081 (http) with
context path ''
2020-04-12 00:21:40.637 INFO 1 --- [ main] com.microservice.DemoApplication
: Started DemoApplication in 8.519 seconds (JVM running for 9.391)
2020-04-12 00:21:52.209 INFO 1 --- [nio-8081-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]
: Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-04-12 00:21:52.210 INFO 1 --- [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet
: Initializing Servlet 'dispatcherServlet'
2020-04-12 00:21:52.227 INFO 1 --- [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet
: Completed initialization in 17 ms
When I do docker container ls I get below output under "ports":
0.0.0.0:8081->8081/tcp if that helps anyway?
I have referred almost all other posts that suggest to include server.address=0.0.0.0 in application.properties but as I mentioned that has not helped me.
Any idea what I could be doing wrong here? Thanks
If you run your application Production mode then by default it uses HTTPS and you might be using localhost(HTTP) to access the host.
You need to remove the --link in your docker run to access it.
--link is a deprecated Docker feature, so there may be a docker network being created between those two containers. Rendering your -p 8081:8081 useless.

mvn spring-boot:run vs Run

I'm testing spring-boot-devtools with livereload on intelliJ.
I have simple SpringBootApplication that works fine.
When I start the app from maven command "mvn spring-boot:run" all works fine excepting that livereload server dont' start. No message on console appears and the chrome extensions show error that It's not possible to connect to livereload server.
If I start app with (right mousse button/Run Application.java), all works fine even livereload server. Message appears on console and browser is able to connect to livereload server.
Starting app from right mousse button/Run Application.java
Console message
2016-07-13 16:39:47.947 INFO 10440 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-07-13 16:39:48.026 INFO 10440 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2016-07-13 16:39:48.077 INFO 10440 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-07-13 16:39:48.145 INFO 10440 --- [ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8090 (http)
Starting app from mvn command "mvn spring-boot:run"
Chorme extension message:
Could not connect to LiveReload server. Please make sure that a compatible LiveReload server is running. (We recommend guard-livereload, until LiveReload2 comes to your platform.)
Console message. See that not show message LiveReload server is running on port....
2016-07-13 16:38:56.749 INFO 6924 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-07-13 16:38:56.852 INFO 6924 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-07-13 16:38:56.898 INFO 6924 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8090 (http)
Why maven command don't start livereload server?
You need to tell Maven to fork a separate JVM to run your application, rather than it running in the same JVM as Maven:
$ mvn spring-boot:run -Dfork=true

Resources