English 中文(简体)
如何使工厂自动化
原标题:How to autowire factorybean
  • 时间:2010-01-28 08:59:28
  •  标签:
  • java
  • spring

我有一个服务公司,编制服务执行清单:

<bean id="services"
      class="org.springframework.beans...ServiceListFactoryBean"
      p:serviceType="ServiceInterface"/>

我能够利用申请文本获得服务,而没有问题:

    final List services = ctx.getBean("services", List.class));

我也可以成功使用拖拉式建筑器注射:

<bean id="aClass" class="AClass">
    <constructor-arg ref="services"/>
</bean>

但是,如果我试图使依赖性自动化的话。

@Autowired @Qualifier("services") private List services;

然后,我收到<条码>BeanCreationException。 目 录

FatalBeanException: No element type declared for collection [java.util.List]

我正在使用春季3.0。

最佳回答

回答是......。

@Resource(name="services") private List services;
问题回答

例外电文来自DefaultListableBeanFactory,而且由于,该电文可以使你的实地自动化。 清单没有通用类型(见DefaultListableBeanFactory第716条)。

在您的领域内添加一个通用签名,例如,h。

@Autowired @Qualifier("services") private List<Service> services;

一、今天实际发现的情况是,当你需要具体接口的目录时,就不需要<代码>@Qualifiers和任何形式的FactoryBean。 春天将为你们找到并注入候选人。 做不到工作,就是如此。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...