javascript
java的自动装配是什么意思_java – 什么时候在Spring中使用自动装配
我正在讀書(shū)
Pro Spring 3.它有一個(gè)段落,真的讓我困惑。這一段關(guān)于Spring的自動(dòng)裝配。這是一個(gè)摘錄:
In most cases, the answer to the question of whether you should use
autowiring is definitely “no!” Autowiring can save you time in small
applications, but in many cases, it leads to bad practices and is
inflexible in large applications. Using byName seems like a good
idea, but it may lead you to give your classes artificial property
names so that you can take advantage of the autowiring functionality.
The whole idea behind Spring is that you can create your classes how
you like and have Spring work for you, not the other way around …
… For any nontrivial application, steer clear of autowiring at all
costs.
我一直在我創(chuàng)建的應(yīng)用程序中使用@Autowired標(biāo)簽。有人可以解釋什么是錯(cuò)誤的,我應(yīng)該用什么呢?
關(guān)于我現(xiàn)在處理大多數(shù)事情的一個(gè)迷你例子是:
@Service("snippetService")
public class SnippetService {
@Autowired
private TestService testService;
public Snippet getSnippet() {
return testService.getSnippet();
}
}
是否使用自動(dòng)裝配像這樣“錯(cuò)了”還是我錯(cuò)過(guò)了什么?
總結(jié)
以上是生活随笔為你收集整理的java的自动装配是什么意思_java – 什么时候在Spring中使用自动装配的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: java动物飞翔接力赛源程序_java-
- 下一篇: JavaScript中替换字符串中的所有