I'm not sure if I'm going to be any help but first I would try to kill whatever is running on 9001 manually.
I use the command: lsof -i :9001
to get the PID then kill -9 <PID>
.
Then try to run application again, which should run fine. Wait for the shutdown and start again.
I set up a very basic Spring app locally and could not replicate the problem.
package com.example.demo;
import org.springframework.beans.BeansException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
@SpringBootApplication
public class DemoApplication implements ApplicationContextAware {
private static ApplicationContext appContext;
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
((ConfigurableApplicationContext)appContext).close();
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
appContext = applicationContext;
}
}
My yaml file then looks like this:
management:
server:
port: 9001
server:
port: 8080
Would you be able to maybe provide a sample of your config file and where you are calling ConfigurableApplicationContext.close();
?