为什么autodetect选项不适用于我?

时间:2010-08-23 17:57:18

标签: java eclipse spring

我正在尝试使用autowire =“autodetect”..

在eclipse中,代码建议没有显示我自动检测作为选项..但是它显示了其他值,如byname,bytype,constructor ..

我的申请中缺少什么?

2 个答案:

答案 0 :(得分:5)

它没有向您autodetect提供,因为(根据the documentation),autodetect不是一种选择。有效选项为byNamebyType amd constructor

顺便说一下,这种自动装配是非常老套的。注释@Autowired@Inject可以更好地控制自动装配 - see docs

更新:自Spring 3.x起,autodetect选项已弃用,因此不再出现在文档中。它应该仍然有用(参见javadoc),所以我错误地说它不是一个选项。

答案 1 :(得分:0)

不推荐使用autodetect选项。

在较新版本的Spring Framework 4.1.6中,我得到以下异常:

Caused by: org.xml.sax.SAXParseException; lineNumber: 7; columnNumber: 83; cvc-enumeration-valid: Value 'autodetect' is not facet-valid with respect to enumeration '[default, no, byName, byType, constructor]'. It must be a value from the enumeration.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)

这基本上意味着现在autowire只能有四个可能的值,即[default,no,byName,byType,constructor]

相关问题