我正在尝试从集成测试中的以下Spring配置XML代码段访问MyBean
:
<jaxrs:server name="myResource" address="foo">
<jaxrs:serviceBeans>
<bean id="myBean" class="com.example.bar.MyBean" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<!-- ... -->
</jaxrs:providers>
</jaxrs:server>
我的测试看起来像这样:
@Resource(name = "myBean")
MyBean b;
//...
当我运行它时,我得到了
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.example.Test': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'myBean' is defined
将id
添加到上面的bean没有帮助(之前我使用过@Autowired
)。
如何从我的测试中的jaxrs:serviceBean
部分访问该bean?