0

I am developing a cron in that i am using a web client to send a post request to a rest api. I don't want to keep the embedded server on, as cron need to complete its task, in few seconds. But when i don't use the server by:

spring.main.web-application-type=none

it shows the error Connection prematurely closed BEFORE response; nested exception is reactor.netty.http.client.PrematureCloseException: Connection prematurely closed BEFORE response as it need the server to work, what can i do to stop the server after the response.

I have tried

server.shutdown=graceful
spring.lifecycle.timeout-per-shutdown-phase=20s

but its not doing anything (i am using intellij ide)

Update: I tried

SpringApplication.exit(context, (ExitCodeGenerator) () -> 0);

But getting Caused by: java.lang.IllegalStateException: org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext@37c7595 has been closed already

Asim
  • 51
  • 7

1 Answers1

0

This will make sure that the SpringBoot application is closed properly and the resources are released back to the operating system,

@Autowired
private ApplicationContext context;

------------------
------------------
int exitCode = SpringApplication.exit(context, (ExitCodeGenerator) () -> 0);
System.exit(exitCode);

original question link

Istiaque Hossain
  • 2,157
  • 1
  • 17
  • 28
  • Oh its stopping but an error is coming: `Caused by: java.lang.IllegalStateException: org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext@37c7595 has been closed already` – Asim Feb 16 '21 at 05:54