- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
要点是 Spring Batch (v2) 测试框架具有带有 @Autowired
注释的 JobLauncherTestUtils.setJob
。我们的测试套件有多个 Job
类提供者。因为这个类不是我可以修改的东西,所以我不确定我如何才能限定它 Autowiring 的作业,这可能因测试而异。
STDOUT [WARN ] [2015.04.15 11:14:42] support.GenericApplicationContext - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobLauncherTestUtilsForSnapshot': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.batch.test.JobLauncherTestUtils.setJob(org.springframework.batch.core.Job); nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.batch.core.Job] is defined: expected single matching bean but found 2: coverageRuleBatch,generateMetricsSnapshotJob
我已经尝试添加这个被识别的 JavaConfig,但错误提示它仍在自动调用 setJob
@Configuration
public class SpringTestConfiguration
{
@Bean
public JobLauncherTestUtils jobLauncherTestUtilsForSnapshot( final Job generateMetricsSnapshotJob )
{
JobLauncherTestUtils jobLauncherTestUtils = new JobLauncherTestUtils();
jobLauncherTestUtils.setJob( generateMetricsSnapshotJob );
return jobLauncherTestUtils;
}
}
注意:我不需要 JavaConfig 解决方案,但它会很好。另外,如果可能的话,我希望仍然 Autowiring JobRepository 等字段,因为只有一个。
最佳答案
当我遇到同样的问题时,我的解决方案是限制组件扫描,以便在测试上下文中只创建一个作业 bean。
@Configuration
@ComponentScan(basePackages={
"com.example.batch.jobs.metrics", //package where generateMetricsSnapshotJob is the only job
"com.example.batch.common",
"..."
})
public class SpringTestConfiguration
{
@Bean
public JobLauncherTestUtils jobLauncherTestUtils()
{
//generateMetricsSnapshotJob and other requirements will be autowired
return new JobLauncherTestUtils();
}
}
您可能需要调整您的包结构才能使其正常工作。
关于java - 我如何才能限定我不使用的 Autowiring 器 "own",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29655796/
在 Haskell 中,我可以导入由其名称或快捷方式名称限定的模块,如下所示: import qualified Data.List as List import qualified Data.Map
我在头文件中有以下函数声明: extern void flash(const char *message, const enum msg_type type); 基本上,它有两个参数并将相应的消息推送
我遇到了一个我似乎无法理解的小问题。 我正在我的数据库中搜索一个用户一个月内收到的评论总数,然后绘制成图表。 我遇到的问题是在我的 SQL 语句中使用 MONTHNAME 如果我使用 $this->d
根据 this answer , 常量不应该被删除,因为它们可能一开始就没有分配。但是,在某些情况下我想保护动态分配的数据。例如,在管理用户 session 时†,我想确保像当前用户名这样的数据不会被
我正在处理一个大型 C++ 项目。我有一堆在项目的子集中使用的宏,但我不想将它们导出到任何地方,以避免污染不相关的代码。 现在,我的许多文件看起来像 #include // defines MACR
谁能解释为什么代码无法编译。 template struct Base { T a; Base(const T argB) : a(argB){} }; template struct Der
我正在阅读 C++-Primer(作者:Josée Lajoie 和 Stanley B. Lippman),这时我看到了有关顶级和低级 const 的部分。在一段中,它说当复制对象时,顶级 cons
我有一大块 CSS,我想将其“作用域”到特定的 HTML block 。我正在生成一个唯一的 ID,然后将其设置在 HTML block 上,然后想用相同的 ID 包装 CSS block ,以便这些
我正在尝试为接受三个参数的函数创建一个通用接口(interface)。填写第一个参数时,第二个参数的选项应该在第一个参数的范围内。第三个参数应该在第二个参数的范围内。 我当前的代码如下所示: type
似乎 C++11 和 C++14 对待纯右值的 cv 限定不同。 C++11 坚持自 C++98 以来一直存在的“经典”方法:根据 3.10/4 “非类纯右值始终具有 cv 非限定类型”。 C++14
这个问题在这里已经有了答案: Stripping all qualifiers from a function type (1 个回答) 关闭去年。 我想编写一个模板,它接受一个指向成员函数的指针(
有时在引用同一类(或基类)的其他实例成员的实例成员中阅读代码可能会造成混淆: public void MyMethod() { Where = did + AllTheseWeirdThing
因此,在使用 constexpr 时,MSVC (Visual Studio 2012) 在尝试使用这个简单的程序(包括省略)使用 constexpr 关键字限定我的函数时给了我一个错误: const
这是我的 html(在 Twig 模板中) {{folder.name}} 我正在尝试从“data-jstree”获取“type”的值。 我试过用 var node_id = ref.get_node
当我尝试编译以下函数时出现错误。 string& foo(){ return "Hello World"; } Error: 1 IntelliSense: a reference of type
我有以下情况: 一个函数创建一个字符串数组,然后将其传递给一堆其他函数。这些其他函数不应修改外部指针指向的指针或字符串本身,因此我将它们设为常量。 最小的例子: void function(const
我希望能够限定 XHTML 文档中的 KnockOutJS 属性。 这是我想做的: My name is:
我正在浏览 Programming with Objective-C Apple 提供的文档。 我正在尝试理解以下段落,但到目前为止,无法理解。 @protocol XYZPieChartViewDa
给定两个 cv-unqualified 非数组对象类型 T1和 T2 , 可以表达 true ? std::declval() : std::declval()曾经有过 cv 限定的数组或函数类型吗?
我是一名优秀的程序员,十分优秀!