what's wrong with the embeded tomcat - spring

Unable to run my project
I am just learning Springboot, following instruction from internet I set up a new project, I use Eclipse Oxygen + Maven (with Embedded Tomcat) + Springboot , I followed the instruction to run the project, but got following error message. I changed the port many times by revising "application.properties" file, but it didn't work. I checked all the ports, their states are "listening".
2019-07-03 04:04:16.256 ERROR 16132 --- [ main] org.apache.catalina.util.LifecycleBase : Failed to start component [Connector[HTTP/1.1-17500]]
org.apache.catalina.LifecycleException: Protocol handler start failed
at org.apache.catalina.connector.Connector.startInternal(Connector.java:1001) ~[tomcat-embed-core-9.0.13.jar:9.0.13]
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.

confirm To you can not use Same Port "8080" More Then One Application And also confirm to another application is not using same port
(Example:- you are going to run your application on Spring with Port 8080 and in Background Another application already was allocated port like XAMPP OR WAPP)

Check Listening Port
Make sure that new port you are going to set is not being used by
other processes. You can check the listening port as below
After Changing the port, Close and Reopen the Project and do Clean, Rebuild your
Project.
PowerShell
Get-Process -Id (Get-NetTCPConnection -LocalPort portNumber).OwningProcess
cmd
C:\> netstat -a -b
Solution
Kill Process on Port 8080 from cmd
netstat -ano | findstr :<yourPortNumber>
taskkill /PID <typeyourPIDhere> /F
OR Change the Port
Update via a properties file.
server.port=8888 # Server HTTP port.
Update via a yaml file.
server:
port: 8888

Related

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

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.

<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.

Cannot connect to Container-optimized-os (running a spring-boot application using docker) using external ip

I have created a Google compute instance with Container-optimized-OS image.
I have configured the firewall to allow http and https.
I am using the docker image with spring boot application which connects to cloudsql. When I use run command on compute engine instance ssh, i.e. (docker run --rm name), the spring boot app is started successfully.
When I try to access the webservices through compute engine instance external ip, it is not working.
I went through a different question, and found that I should try using the sudo wget http://localhost command on the instance cli first and if it is good then everything should be good. But I am getting a connection refused message on 127.0.0.1:80.
I also tried the command to open port from Container optimized OS, I.E.
sudo iptables -w -A INPUT -p tcp --dport 80 -j ACCEPT , nothing is working.
The default port for Spring Boot is 8080 and not 80.
Run this command inside the instance container to see what ports are in LISTENING state:
sudo netstat -tulpn | grep LISTEN
You can redirect port 80 to port 8080 with this command:
sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
Note: This iptables command only redirects port 80 to 8080 on network interfaces. This has no effect for localhost or 127.0.0.1.
For Google Compute Engine instances you do not need to enable ports using iptables. This is done via Google VPC firewall rules. You can use both but make sure you understand exactly what you are configuring and the side effects.
Note: Your Spring Boot application needs to listen on 0.0.0.0 and not 127.0.0.1 nor localhost. The last two are internal only addresses. 0.0.0.0 means listen on all network interfaces.
Note: Do not use sudo in front of wget. This is not necessary.
First, confirm what port your springboot application uses - if it's 8080 or 80. This depends on what you have configured inside application.properties file. This port is referred to as ContainerPort in below steps.
Execute docker run <image-name>:<tag>. This will run the image and show container logs on the console. If there is something wrong with your spring-boot app, the logs will show that and the container will shutdown. Press Ctrl+C to stop the container and return to shell.
If there is no error in step 1 run docker run -d -p<HostPort>:<ContainerPort> <image-name>:<tag>. Here HostPort is any free port in your GCP host VM and ContainerPort is the port used by your spring boot application within the container. Option d starts your container in detached mode.
Run docker ps and make sure that the container started in step 2 is running. It may not run if there is an error - for example if the HostPort you specified is already in use.
If step 3 shows that the container is running, execute curl http://localhost:<HostPort>/<End-Point-Path>. Here End-Point-Path is a valid path to a working endpoint within the container. If the endpoint is correct you should see expected result from the spring-boot app in the console.
Navigate to Google Cloud Console -> VPC network -> Firewall rules and add a firewall rule to open HostPort on your GCP VM.
Access your endpoint via the VM's external IP with URL - http://<VM-External-IP>:<HostPort>/<End-Point-Path>
Unless there is an application issue with your spring-boot app these steps should get you going.
I was able to build the correct solution by your help (John Hanley and Cyac).
I am combining both solutions in order to help the next person facing this.
As told by John, by default Spring boot uses port 8080, not 80 and as specified by Cyac you need to specify the port as 80 explicitly in application.properties file using
server.port=80
Make sure you expose the port 80 in docker image
On GCP Contaier optimized OS make sure you have allowed traffic for HTTP and HTTPs
Run command:
sudo iptables -w -A INPUT -p tcp --dport 80 -j ACCEPT
Run docker using:
docker run -p 80:80 SPRING_IMAGE.
Where SPRING_IMAGE is the name of the docker image with spring boot build.
Test by using curl http://localhost/ENDPOINT_NAME , e.g. http://localhost/shops/all

Tomcat8 as a Windows service - listen on network socket

Are there difference in the way how Tomcat8 is bind to windows network socket whe is started from console (by startup.bat) of if is started as a windows service? I am not able to connect to application web if Tomcat is started as a windows service. See netstat if started from console:
C:\Program Files\Apache Software Foundation\apache-tomcat-8.0.0-RC10\bin>netstat -abnop tcp | grep -i -B2 8089
[java.exe]**
TCP 0.0.0.0:8089 0.0.0.0:0 LISTENING 6016
See netstat if started as a service (notice different name of listening process):
C:\Program Files\Apache Software Foundation\apache-tomcat-8.0.0-RC10\bin>netstat -abnop tcp | grep -i -B2 8089
[tomcat8.exe]**
TCP 0.0.0.0:8089 0.0.0.0:0 LISTENING 2856
Windows service was created by documentation: 'service.bat Install'.
"Image path" of service is: "c:\Program Files\Apache Software Foundation\apache-tomcat-8.0.0-RC10\bin\tomcat8.exe" //RS//Tomcat8
What am I doing wrong?
1st thing you should do:
Check your Windows Firewall :)
When you say "different name of listening process", are you talking about the PID? Have you tried to use "ProcessExplorer" (http://technet.microsoft.com/en-us/sysinternals/bb896653) to check the discrepancies between the Java processes that are created when you start the Tomcat instance?
When you mouse over the java process you can see the JVM arguments assigned for that JVM instance, also, when you right-click the java.exe process you can check its properties, on the "TCP/IP" tab you can check if your Tomcat is listening on the right port. Try to start Tomcat using both approaches and take a closer look with ProcessExplorer, that should help you identify any misconfiguration.

Resources