阻止运行实现了CommandLineRunner接口的Spring Boot任务。

huangapple go评论73阅读模式
英文:

Prevent running an spring boot task which implements CommandLineRunner

问题

我正在编写一个使用Cucumber进行集成测试的Spring Boot任务(非Web应用程序),该任务实现了CommandLineRunner。由于commandLineRunner的默认行为,即使将cucumber feature作为JUnit运行,它也会先运行任务,然后再返回到cucumber feature文件。相反,我希望它不要运行任务,并且一旦配置完成,控制应该回到feature文件。

我该如何阻止CommandLineRunner运行其run方法?

英文:

I am writing a spring boot integration test using cucumber for a task (non web application) which implements CommandLineRunner. Due to default behavior of commandLineRunner, even after running the cucumber feature as junit, it runs the task first and then come backs to cucumber feature file. Instead I expect it not to run the task and control should come to feature file once the configuration is done.

How can I prevent CommandLineRunner from running its run method?

答案1

得分: 1

将@Bean声明添加@Profile("!profile_name")注解,然后在需要排除该配置时设置该配置文件。

英文:

Add @Profile(“!profile_name”) annotation to the bean declaration and then set that profile when you need to exclude it

huangapple
  • 本文由 发表于 2020年10月22日 17:09:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/64478978.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定