Strange behavior of server.port property in Tomcat - spring

Actually, it is not a problem, but a strange thing I would like to understand. I use SpringBoot2 with embedded Tomcat. And I've added self-signed SSL certificate. This is pretty usual config:
server.ssl.key-store-type=PKCS12
server.ssl.key-store=classpath:keystore.p12
server.ssl.key-store-password=123456
server.ssl.key-alias=tomcat
server.port=8443
And I made a connector, to force http -> https redirect, like in many examples:
private Connector getHttpConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
connector.setPort(8080);
connector.setSecure(false);
connector.setRedirectPort(8443);
return connector;
}
If I would not specify server.port property in my config, I will see the following error:
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.
But if I will, I will see following:
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s):
8443 (https) 8080 (http) with context path ''
Why server.port starts to point at https port??? Even sources of springframework.boot.autoconfigure.web.ServerProperties says that it is
/**
* Server HTTP port.
*/
Is it ok, or I've got something strange in my server? Or this is how Conectors works? :) Thank you

By default, the embedded server start on port 8080 if you don't give any value for server.port in the properties file
And you are also specifying connectors port as 8080 (connector.setPort(8080);)
Hence you are getting port conflicts.

Related

This springboot ssl never works

I configured ssl on springboot correctly:
server.port=8443
server.ssl.key-store=classpath:springboot.p12
server.ssl.key-store-password=*****
server.ssl.key-store-type=PKCS12
It always says the same whatever port I try:The Tomcat connector configured to listen on port 8443 failed to start. The port may already be in use or the connector may be mis-configured. Action:Verify the connector's configuration, identify and stop any process that's listening on port 8443, or configure this application to listen on another port. Springboot will not start the application, it's so terrible as a framework with no way to debug it.
Any experienced developer could know such a bug that stuck me forever?!
Its apache2 use it:
SSLEngine On
SSLCertificateFile /abc.crt
SSLCertificateKeyFile /abc.key
SSLCertificateChainFile /abc.ca-bundle
It has to use this way exactly to make it work:
https://mkyong.com/spring-boot/spring-boot-ssl-https-examples/

spring-boot auto change port if port is already used

I am using Windows command to run my spring-boot application with emblemed tomcat. Beside, I need to run many console application using CommandlineRunner. Off cource I am facing port in use issue.
***************************
APPLICATION FAILED TO START
***************************
Description:
Web server failed to start. Port 8080 was already in use.
Action:
Identify and stop the process that's listening on port 8080 or configure this application to listen on another port.
I can set port in every console application but I need to run at least 10 console application at the same time.
Do I have any config or solution for application auto-change port?
You can auto generate port number to get rid from Port was already in use. just put server.port= 0 in properties or yml. It is auto generate server port in console.
application.properties
server.port= 0
application.yml
server:
port : 0
console

Spring cloud client trying to run on server port 8888

The config server is up and the client is able to fetch the properties from config server.
HTTP GET http://localhost:8888/account-service/dev/config
Accept=[application/json, application/*+json]
Response 200 OK
But the problem is, client service is trying to start on config server port 8888. I have set server.port=8080 in the client but still not working.
***************************
APPLICATION FAILED TO START
***************************
Description:
Web server failed to start. Port 8888 was already in use.
Am I missing any configuration here? Highly appreciate any help.
Config server application.properties,
spring.application.name=config-server
spring.cloud.config.profiles=dev
spring.cloud.config.server.git.uri=REPO_URL
server.port=8888
Finally, I was able to find the solution. When I was trying to start client service, server.port was also getting overridden with config server port. I added server.port=8080 in the properties file for the client service profile in config repo (account-service.properties) and it worked.

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

Resources