Spring boot port opens randomly when running in Citrix machine - spring

I have a Citrix machine and I have to run a web service there (developed using Spring Boot). It is a Windows 10 host. There is a strange behaviour - the port is randomly chosen instead of the configured port 8090.
I checked my application.properties and it is clearly showing
server.port=8090
There is no issue with the code, if I run it from any other machine, it will start in port 8090 as expected.
It even prints out in the Citrix machine that the Tomcat server is initialised with port 8090. But finally it starts at a random port (22345) as seen in the logs below. If I stop and start again, it will start in another port (maybe 23466).
2021-06-28 13:45:52.490 INFO 31792 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8090 (http)
......
......
2021-06-28 13:45:53.348 INFO 31792 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 22345 (http) with context path ''
2021-06-28 13:45:53.355 INFO 31792 --- [ main] com.sreejesh.MainApplicationClass : Started MainApplicationClass in 3.701 seconds (JVM running for 4.798)
I have even tried to override it in command line:
java -jar MyApp.jar --server.port=8090
Still the result is same (as if someone is strangely overwriting server.port=0 to start in a random port).
I want to reiterate that everything works fine in my local machine as expected. Only in Citrix machine this strange behaviour exists.
Any clue as to why this happens? Thank you for your time.

Related

Tomcat on port 8080 failed using Spring boot Java

i am beginner of spring boot. when i run the spring boot application i ran into the problem with The Tomcat connector configured to listen on port 8080 failed to start. Spring boot
i don't how to solve the problem. i have install mysql when i ran the mysql it port also 8080. so how to sort out the problm.
***************************
APPLICATION FAILED TO START
***************************
Description:
The Tomcat connector configured to listen on port 8080 failed to start. The port may already be in use or the connector may be misconfigured.
Action:
Verify the connector's configuration, identify and stop any process that's listening on port 8080, or configure this application to listen on another port.
Seems like 8080 port is already used by some other process.
Change the port of spring-boot tomcat port by adding the server.port=8090 in application.properties.
Change 8090 to any port you want to use.
Your 8080 port is already used by some other process.
Change the port of spring-boot server.port=8090 in application.properties.
You can change your application run server port any port number to if that port number would not belong to any other process on your computer.
and another thing if you use IntelliJ idea to develop, accidentally close your IDE without proper way this error may have occurred {personal experience}.
It is not necessarily required to change the port, you can just end the process of it to release it in your spring application
Open cmd as administrator and enter the following commands:
netstat -year | findstr 9330
Once you find the process number, type it in the highlight of the following command:
taskkill /F /PID <Process ID>
The result should appear as follows:
SUCCESS: The process with PID < Process Id > has ended.

Is Eureka running on 8761 or 8080?

I've created a new spring boot project with "spring-cloud-starter-netflix-eureka-server" dependency. Also have added "#EnableEurekaServer" annotation and launched the spring boot app.
I see the below log messages
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
c.n.eureka.cluster.PeerEurekaNodes : Adding new peer nodes [http://localhost:8761/eureka/]
From above, as I understand. Tomcat is running on port 8080 and eureka server is running on port 8761.
If so,
How come the Eureka Dash board is accessible at http://localhost:8080/ ? When the eureka server is running on port 8761 ?
On one of the client, I configured the following in the .properties file
eureka.client.service-url.defaultZone=http://localhost:8761/eureka/
Above, I specified the Eureka server location. But, why is the client unable to register?
Thanks!
By default it works on 8761, so configure server.port=8761

<SpringBoot> Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-12-28 09:49:48.561 ERROR 482 --- [ main] o.s.boot.SpringApplication : Application run failed
when I try to start server with command:
java -jar jin-alpha-1.0.jar
under AWS Ubuntu linux server.
In case of trying to local start server was success.
The Changed port is suspicious the reason why before changed It work.
I changed Server port from 8080 to 80.(The reason why AWS http allowed only 80 port)
Local Case : The port of Tomcat server ==> 8080 and 80, Both of them are work. and Stared
AWS Ubuntu : Start with 8080 is work but 80 is not work and Error displayed Above.
I got solution.
I Changed Tomcat port from 80 to 8080. so Server started under Aws ubuntu.
(I don't still know why 80 port is not work under Aws Ubutu)
and Add "Custom TCP Rule" with 8080 port Range.
These are called Priviliged ports on *nix systems. The TCP/IP port numbers below 1024 are special in that normal users are not allowed to run servers on them. This is a security feaure, in that if you connect to a service on one of these ports you can be fairly sure that you have the real thing, and not a fake which some hacker has put up for you.
The normal port number for W3 servers is port 80. This number has been assigned to WWW by the Internet Assigned Numbers Authority, IANA.
When you run a server as a test from a non-priviliged account, you will normally test it on other ports, such as 2784, 5000, 8001 or 8080.
Hope this explains why you cannot run on 80. There are workarounds like running as root. Which I dont recommend as if some hacker gets access to the service then they get root privileges on the box. You need to be careful not running services on such ports.

Why Spring Boot 1.5.9.RELEASE starting on two ports by default?

I am using Spring Boot 1.5.9.RELEASE and it starts on two ports by default.
Tomcat initialized with port(s): 8080 (http) 8090 (http)
Tomcat started on port(s): 8080 (http) 8090 (http)
I have tried setting different port using server.port but that overrides only first port 8080 to a different one and 8090 remains. Also tried to change actuator port with management.port to a different one.
I see spring Boot 2.x doesn't have this issue. Any reason why spring boot 1.x runs on two ports by default and how to run on single port?
application.properties
server.context-path=/test-app
endpoints.actuator.enabled=true
management.security.enabled=false
management.health.defaults.enabled=true
management.health.mail.enabled=false
management.port=8981

server.port in command line not working with spring cloud config server and eureka server

I am studying spring could. What I have now is a spring cloud config server and eureka server.
Code for Config Server
#SpringBootApplication
#EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
application.properties
spring.application.name=config-server
spring.cloud.config.server.git.uri=https://github.com/vincentwah/spring-cloud-config-repository/
server.port=7001
Code for Eureka server
#SpringBootApplication
#EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
bootstrap.properties
spring.application.name=eureka-server
spring.cloud.config.uri=http://localhost:7001/
The config for eureka-server is https://github.com/vincentwah/spring-cloud-config-repository/blob/master/eureka-server.properties
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/
server.port=1111
When I start eureka server, I'd like to change the port, so I run below command
java -jar target/eureka-server-0.0.1-SNAPSHOT.jar --server.port=1234
However, the server is still started with port 1111
2017-01-03 14:04:11.324 INFO 6352 --- [ Thread-10] c.n.e.r.PeerAwareInstanceRegistryImpl : Changing status to UP
2017-01-03 14:04:11.339 INFO 6352 --- [ Thread-10] e.s.EurekaServerInitializerConfiguration : Started Eureka Server
2017-01-03 14:04:11.492 INFO 6352 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 1111 (http)
2017-01-03 14:04:11.493 INFO 6352 --- [ main] c.n.e.EurekaDiscoveryClientConfiguration : Updating port to 1111
2017-01-03 14:04:11.500 INFO 6352 --- [ main] com.example.EurekaServerApplication : Started EurekaServerApplication in 27.532 seconds (JVM running for 29.515)
I think I am not doing wrong with --server.port in command line. Does anybody encounter same issue?
Spring Cloud Config, by default, overrides local configuration. It is meant to be the source of truth. You could use profiles so the port is not defined with a particular profile. You could also disable the config client if it's not really needed (in tests for example).
There are also options to allow overrides.
The property sources that are added to you application by the
bootstrap context are often "remote" (e.g. from a Config Server), and
by default they cannot be overridden locally, except on the command
line. If you want to allow your applications to override the remote
properties with their own System properties or config files, the
remote property source has to grant it permission by setting
spring.cloud.config.allowOverride=true (it doesn’t work to set this
locally). Once that flag is set there are some finer grained settings
to control the location of the remote properties in relation to System
properties and the application’s local configuration:
spring.cloud.config.overrideNone=true to override with any local
property source, and
spring.cloud.config.overrideSystemProperties=false if only System
properties and env vars should override the remote settings, but not
the local config files.
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/
server.port=1111
spring.cloud.config.allowOverride=true
spring.cloud.config.overrideNone=true
spring.cloud.config.overrideSystemProperties=false
This is working.

Resources