我相信这里有两件事令人困惑。在本章中,“自动装配”的含义是标记Bean,以自动检测和注入依赖项。这可以通过设置“ autowire” bean属性来实现。
实际上,这与
@Autowired在显式指示字段或设置器的位置进行依赖注入相反。
在这里看看:http :
//static.springsource.org/spring/docs/3.1.x/spring-framework-
reference/html/beans.html#beans-factory-
autowire。
解释一下,假设你有
public class SnippetService { private TestService testService; public Snippet getSnippet() { return testService.getSnippet(); } public void setTestService(TestService testService) { this.testService = testService; }}如果定义了bean:
<bean autowire="byType"/>
TestService在这种情况下,spring将通过调用setTestService setter 尝试注入匹配类型的bean
。即使您没有使用
@Autowired。这确实很危险,因为某些二传手可能并不意味着在春季被召唤。
如果设置自动装配=“否”,什么都不会被注入,除非标记,以便有
@Autowired,
@Resource,
@Inject。



