-
Notifications
You must be signed in to change notification settings - Fork 396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Context don't close #863
Comments
Do you have something in |
I have not modified or customized the application context. package com.tam;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.ApplicationPidFileWriter;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.shell.command.annotation.CommandScan;
@CommandScan
@EnableScheduling
@EnableAspectJAutoProxy
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication(Application.class);
springApplication.addListeners(new ApplicationPidFileWriter());
springApplication.run(args);
}
} Now I have implemented a Work Around like this: package com.tam.cli.components.aspects;
import com.tam.cli.utils.ShellHelper;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class ShellAspects {
@Autowired
ShellHelper shellHelper;
@Pointcut("@annotation(com.tam.cli.components.annotations.AIShellExecutionTime)")
public void shellLogPointCut() {
// Pointcut
}
@Pointcut("@annotation(org.springframework.shell.command.annotation.Command) && execution(* com.tam.cli.components.cmd..* (..))")
public void shellRunModePointCut() {
// Pointcut
}
@Around(value = "shellLogPointCut()")
public Object shellExecution(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
Object proceed = null;
long startTime = System.currentTimeMillis();
try {
proceed = proceedingJoinPoint.proceed();
} catch (Exception ex) {
shellHelper.printError("Operation got exception");
throw ex;
}
long endTime = System.currentTimeMillis();
long executionTime = endTime - startTime;
shellHelper.printInfo("Operation executed in ".concat(String.valueOf(executionTime)).concat("ms"));
return proceed;
}
@After("shellRunModePointCut() && args(.., interactive)")
public void shellRunMode(JoinPoint joinPoint, boolean interactive) {
if (!interactive) {
shellHelper.printInfo("Command completed !");
System.exit(0);
}
}
} With an Aspect shellRunModePointCut I check if the method contains interactive param and if it is true the program force exit. |
It's One other more clean workaround is to request context close when boot notifies
This works as shell logic is executed with boot's |
Thanks for your help. |
- spring.shell.context.close=true adds ApplicationListerner which attempts to close context with ApplicationReadyEvent. - Relates spring-projects#863
- Relates spring-projects#863
HOW TO USE
WHAT I'M DOING
I'm using new annotation model for implement a command line.
In my use case i need that my commands are executable with non-interactive mode.
I need after command completion that session will be closed automatically.
WHAT HAPPEN
This is my custom command
This is my application.properties where I disabled scrips and interactive mode:
When I run the command in non-interactive mode The program wait the SIGTERM:
The text was updated successfully, but these errors were encountered: