- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在 Spring 测试中禁用 @Schedule,但我找不到办法。
我尝试为测试环境创建不同的配置类,但任务仍然被触发。这是配置:
@Configuration
@EnableTransactionManagement
@EnableScheduling
@ComponentScan({"de.package"})
@PropertySource(name="application.properties", value="classpath:application.properties")
public class PersistenceJPAConfig {
...
}
这是测试环境配置。刚刚删除@EnableScheduling注解
@Configuration
@EnableTransactionManagement
@ComponentScan({"de.package"})
@PropertySource(name="application.properties", value="classpath:application.properties")
public class PersistenceJPATestConfig {
...
}
在测试中我使用:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { PersistenceJPATestConfig.class }, loader = AnnotationConfigContextLoader.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class GetArticlesTest {
...
}
但是当我运行测试时任务仍然被触发..有什么方法可以在运行测试时停止执行任务吗?
最佳答案
由于您两次都在同一个包上使用@ComponentScan,因此 spring 似乎也在加载其他配置。
您可以使用一些配置文件来过滤它,例如将其添加到您的 PersistenceJPATestConfig
@Profile("test")
在你的 JUnit 类上添加这个注解,这样它将使用“测试”配置文件执行
@ActiveProfiles("test")
编辑:你的主配置也应该被分析,所以当它的配置文件不活动时它会被忽略,所以你应该在主配置类上添加另一个@Profile,其配置文件不同于“test”
关于java - 在 Junit 测试中禁用 Spring @EnableScheduling,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39033456/
我正在按照此示例在示例项目中创建计划任务:https://spring.io/guides/gs/scheduling-tasks 它说,@EnableScheduling ensures that
有没有办法根据应用程序属性使@EnableScheduling 成为条件?也可以根据属性禁用 Controller 吗? 我想要实现的是让相同的 spring boot 应用程序用于处理 Web 请求
当我运行单元测试时,它会调用我的计划任务。我想防止这种行为,这是由于我的主应用配置中有 @EnableScheduling 造成的。 如何在我的单元测试中禁用它? 我遇到过这个question/ans
我创建了一个类,其中的方法应每 5 秒运行一次。它们看起来像这样: @Configuration @EnableScheduling public class MyClass { @Sched
我想在 Spring 测试中禁用 @Schedule,但我找不到办法。 我尝试为测试环境创建不同的配置类,但任务仍然被触发。这是配置: @Configuration @EnableTransactio
我一直在研究如何使用 Java 8 和 spring 在运行时更改作业的频率。 This question非常有用,但并没有完全解决我的问题。 我现在可以配置下一次执行作业的日期。但是如果将延迟设置为
我关注了very simple examples在线在 Spring 中设置 cron 作业,但我每次都在 Tomcat 启动日志中收到此错误: 2015-05-25 00:32:58 DEBUG S
因为“只有返回无效的方法可以用@Scheduled注释”,当我使用@Bean配置时如何使用Spring Batch和Spring Scheduler Task的xml配置?您可以在下面找到我的完整配置
我在小枝应用程序中工作 其中有一个类scheduledJob,具有以下注释 @Configuration @EnableScheduling @Component public class Sched
我是一名优秀的程序员,十分优秀!