@Inject Warning Eclipse JBoss DS;注入接口 - 没有具体的类

时间:2016-10-26 19:40:57

标签: spring dependency-injection

我正在使用Spring 4.2.4和MyFaces 2.2.9,Java 1.8。

我按照这个例子创建了一个工厂模式; Spring: implementing the Factory pattern

我们有界面;

package com.jsf2.strategy;

public interface PrintStrategyFactory {         
    IPrintStrategy getStrategy(String strategyName); 
}

applicationContext.xml ;

<bean id="printStrategyFactory" class="org.springframework.beans.factory.config.ServiceLocatorFactoryBean">
    <property name="serviceLocatorInterface" value="com.jsf2.strategy.PrintStrategyFactory" />
</bean>

<alias name="A4Portrait" alias="A4P" />
<alias name="A4Landscape" alias="A4L" />
<alias name="A5Portrait" alias="A5P" />
<alias name="A5Landscape" alias="A5L" />
<alias name="A4Portrait" alias="DEFAULT" />

所以PrintStrategyFactory只有没有具体的类,只有接口。

我正在尝试使用CDI语法来注入接口;

@Component
@Scope("singleton")
public class TestBean {

@Inject  // I get warning here
@Autowired // NO WARNING
private PrintStrategyFactory printStrategyFactory;

@PostConstruct
private void init() {
. . . . . .

@Autowired; 不显示警告

使用@Inject显示;

  

没有豆有资格注射到注射点[JSR-299§5.2.1]

在运行时,两种方式都有效,但我正在尝试使用CDI语法。

如果我添加一个实现接口的Concrete类,警告就会消失。

我应该只是压制警告还是有替代解决方案?

0 个答案:

没有答案
相关问题