Spring Boot Version: 2.1.5.RELEASE
I have a simple Spring Boot MVC Application that uses Redis for spring session storage.
spring:
session:
store-type: redis
redis:
flush-mode: on-save
namespace: spring:session
redis:
host: localhost
password:
port: 6379
database: 0
When I run it on STS ("Run as" - "Spring Boot App"), it uses my Redis installation for session storage. I can see the keys being added on Redis (keys *).
But, when I run it using bootRun on command prompt, everything related to sessions seems to work fine, but I don't see any keys on the Redis server. It seems like it is not even connecting to my Redis server. I can even safely shutdown Redis without affecting anything.
I have made sure that I have the same system properties between the two modes of run. What could be the difference? Where could it be connecting to in the latter scenario?
[EDIT]
Something I noticed in the log files after enabling TRACE on org.springframework.session -
When run on STS, I see these log entries (expected) -
2019-06-27 14:23:47.086 DEBUG No session found by id: Caching result for getSession(false) for this HttpServletRequest. | HP-20111108 | org.springframework.session.web.http.SessionRepositoryFilter.SESSION_LOGGER | nio-8080-exec-1
2019-06-27 14:23:47.087 DEBUG A new session was created. To help you troubleshoot where the session was created we provided a StackTrace (this is not an error). You can prevent this from appearing by disabling DEBUG logging for org.springframework.session.web.http.SessionRepositoryFilter.SESSION_LOGGER | HP-20111108 | org.springframework.session.web.http.SessionRepositoryFilter.SESSION_LOGGER | nio-8080-exec-1
java.lang.RuntimeException: For debugging purposes only (not an error)
at org.springframework.session.web.http.SessionRepositoryFilter$SessionRepositoryRequestWrapper.getSession(SessionRepositoryFilter.java:332) [spring-session-core-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.session.web.http.SessionRepositoryFilter$SessionRepositoryRequestWrapper.getSession(SessionRepositoryFilter.java:354) [spring-session-core-2.1.6.RELEASE.jar:2.1.6.RELEASE]
.....
2019-06-27 14:24:00.003 DEBUG Cleaning up sessions expiring at Thu Jun 27 14:24:00 CDT 2019 | HP-20111108 | org.springframework.session.data.redis.RedisSessionExpirationPolicy | pool-2-thread-1
When run using bootRun, this is the only log entry I see -
2019-06-27 14:27:05.936 WARN Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [382] milliseconds. | HP-20111108 | org.apache.catalina.util.SessionIdGeneratorBase | nio-8080-exec-1
Could Tomcat be taking over session management when run using bootRun ? How does that happen?
Dang ! Seems this was my fault. My project in STS was off. This is a Gradle project and I had made some changes on the project and didn't know I had to do a "Refresh Gradle Project". Anyway, they are in sync now and behave similarly, but the sad thing is that it is both behaving the wrong way (doesn't use Redis), but I guess that is a separate issue.
I am running my Tomcat on my IntelliJ IDE. Whenever I stop my server, via the IDE, it never stops the server. Instead, I have to go manually kill it via the following command in my terminal:
ps -ef | grep tomcat
kill -9 <id>
I am not sure what is causing this issue. Is it safe to kill it every time?
IntelliJ IDEA just calls the standard Tomcat shutdown script. If it can't stop the server, the issue is most likely with the application you have deployed. If the app creates threads and doesn't properly terminate them on the server shutdown, Tomcat will not be able to stop gracefully. You can use jstack to see which threads are running and preventing the server shutdown.
I've been playing with spring boot version 1.5.8 release lately. I was able to stand it up as rest web service to handle incoming request.
This is how I activate the service. Note: linux environment.
nohup java -jar fooservice.jar &
Then I tail the nohup.outfile to monitor the start up process, any incoming request, any exception thrown and etc.
My question is how to terminate the instance of the program? I run ps -ef | grep command to find pid of the running instance then run kill -9 command to terminate it.
Is there elegant way to stop the service?
You can shutdown spring boot application by enabling actuator shutdown end point /actuator/shutdown, first we need to enable it here
management.endpoint.shutdown.enabled=true
endpoints.shutdown.enabled=true
And then invoke it
localhost:port/actuator/shutdown
I have a problem with running my sample Spring Boot Application.
When I try to run it, this error occurs:
java.net.BindException: Address already in use: bind
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Unknown Source)
at sun.nio.ch.Net.bind(Unknown Source)
at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source)
at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source)
at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:473)
o.apache.catalina.core.StandardService : Failed to initialize connector [Connector[org.apache.coyote.http11.Http11NioProtocol-8080]]
org.apache.catalina.LifecycleException: Failed to initialize component [Connector[org.apache.coyote.http11.Http11NioProtocol-8080]]
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:106)
at org.apache.catalina.core.StandardService.initInternal(StandardService.java:559)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:814)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at org.apache.catalina.startup.Tomcat.start(Tomcat.java:335)
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:57)
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:52)
at
Is it ok the first time you run it, and run it again you get an error?
If this is the case, You need to stop service before running again.
Here is a way to stop.
Click the stop button that looks like this:
"Address already in use" means, there is already another application running on port 8080. Use your OS tools to find that process and end it, before you start your application, or let your application run on another port. If you use an embedded server in your Boot application, you can specify the following property:
server.port=8085
Of course you can choose whatever port you want.
I have a very simple solution:
As the answer above stated, when you start Spring Boot app, the PID of underneath server(Tomcat or Undertow, or whatever) will be shown in the console; you may start again the app without terminating the former one, especially when you are in debug mode, thus the error. This applies to Intellij, too.
But, if you have started again, the PID is no longer available for you because previous session output is cleared.
So, if you are using Eclipse, just close it, and open Task Manager to terminate other java.exe JVM process. Be sure that you have no other JVM-based services running which cannot be stopped. (Like Kafka server, Apache Storm, etc.)
The Tomcat instance is one of them.
Log shows that server is already started on port 8080. I faced the same problem. go to windows task manager and end process that is javaw.exe, it worked on my application.
Two possibilities
P1.Another Application is using port 8080
Solution:-
a.Stop that application and free port 8080 for your application.
b.Change your application server port, for that create a file named
application.properties in resource folder and add property
server.port = 8085
(8085 can be replaced by any port number of your choice which will not conflict with other
application server ports)
location of application.properties file
snippet of application.properties file
P2. Your application is already running
Solution
a. Pretty simple solution for this situation is stop your currently
running application and rerun it
b.If you want to run multiple instances of your application then keep
current application running change server port as explained above and
run the application the new instance will run of another port.
Even I faced this issue u can just stop the application(there is a stop button on the top toolbar) and restart again it worked for me and I used STS
In the Eclipse situation, check if there are items running in the window "Progress"(Windows > Show View > Progress)
Stop the running process, which might be locking your desired port.
Got the same error.
The springboot application has inbuilt tomcat server which runs on port 8080..if you have any other process currently running on port 8080,The java.net.BindException will raise..so kill the processes which are using 8080 thorugh cmd as follows:
-->
open command prompt as Administrator.
--> netstat -ano | findstr :<PORT>
netstat -ano | findstr :8080
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 10568
TCP [::]:8080 [::]:0 LISTENING 10568
-->taskkill /PID <PID> /F
taskkill /PID 10568 /F
Now if you want recheck your running process by using netstat -ano | findstr :8080 command..
and again restart or rerun our application..
This is for first ever time you wanted to run springboot application.
Hope this might be helpfull,worked for me :)
Second case:
In the first time you run ok right? and run again it got an error? If right, You need stop service before run again..if it is the case follow #Sang9xpro
answer above.
Seems your server is already up. If you are using linux based system, type following command in terminal to check which port is active on your system.
"ps -ef | grep 8080"(or whatever port is mentioned)
Now you need to kill this one if you wish to run the server on same port.
kill -9 8080
Voilla!! Try booting your application once again and it will work.
Extra:
You'll come to me complaining an important application is already listening on mentioned port(8080) and you do not want to kill it. No probs.
Create an application.properties file inside your resource folder and change port to whatever you like.
server.port = 8081
Voilla!! You did it!! :)
Let me know if further clarifications required.
This is because you have run the spring boot application once in your eclipse IDE and closed the application and you assume that the embedded server is stopped. But it is not the case. Even after you closed your application in Eclipse -> Console window, embedded tomcat server is running. What you can do is, run your spring boot application again and look at the console messages. Immediately after Spring Logo, you can find Starting on with PID 16676. This is the PID you need to search in "Wndows Task Manager -> Processes -> PID". Select that process and "End Task". Now if you start your spring boot application, it will start without issues.
Here is my question and i tried it hard to brainstormed with people in my team and with other resources which i have.
I have to go 100's Linux black-boxes to find if Tuxedo Client is running there or not . How can i tell if Tuxedo Client is on each box.
Maybe Tuxedo Server is running on that box may its just installed and not running .How can i different between Then Tuxedo Client and Server.
Is there any procedure or way or any command which i can used and which can tell me if Tuxedo client is there on box or not.
To check if a Tuxedo domain is running in a server, you could check if there is BBL process running.
# ps -ef | grep BBL
For clients, there are many ways that a Tuxedo client's may connect to servers:
Example:
via:
/WS
JOLT
Direct connection
Weblogic Tuxedo Connector (WTC)
Server calling another tuxedo servers (via tdomain)
To verify tuxedo clients conecting via WTC/JOLT there must be a Weblogic Server OR Java process calling tuxedo servers.
# ps -ef | grep java
To verify tuxedo clients that connects via /WS there must be a WSNADDRR defined in the enviroment of the process.
# ps auxeww |grep -i WSNADDR | grep -v grep