Spring Java 配置找不到通过上下文创建的 bean:component-scan



到目前为止,我已经混合了xml和java配置,并取得了非常好的成功,但是有一个用例似乎不起作用。我让 spring 使用组件扫描来配置我的 JAX-RS 资源,并且它们已正确解析:

<context:component-scan
    base-package="<my packages>">
    <context:include-filter type="annotation"
        expression="javax.ws.rs.Path" />
...

但是,如果我尝试在我的 java 配置中调用这些类之一:

HttpInvokerServiceExporter exp = new HttpInvokerServiceExporter();
exp.setService(context.getBean(Users.class));

我收到此错误:没有定义 [com.gecod.allianz.arco.web.restresources.Users] 类型的唯一 bean:预期的单个 bean,但找到 0:

一种解决方案可能是在xml或java配置中声明JAX-RSbean,但这样Resteasy就不会将它们识别为JAX-RS资源。

我想我有竞争条件,有什么提示吗?

看看这是否更好

<beans xmlns="http://www.springframework.org/schema/beans"       xmlns:mvc="http://www.springframework.org/schema/mvc"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"       xmlns:context="http://www.springframework.org/schema/context"       xsi:schemaLocation="        http://www.springframework.org/schema/beans         http://www.springframework.org/schema/beans/spring-beans-3.1.xsd        http://www.springframework.org/schema/context         http://www.springframework.org/schema/context/spring-context-3.1.xsd        http://www.springframework.org/schema/mvc        http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">            <context:annotation-config />    
<context:component-scan base-package="com.blah.blah" />

最新更新