javascript
java的自动装配是什么意思_java – 什么时候在Spring中使用自动装配
我正在讀書
Pro Spring 3.它有一個段落,真的讓我困惑。這一段關于Spring的自動裝配。這是一個摘錄:
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.
我一直在我創建的應用程序中使用@Autowired標簽。有人可以解釋什么是錯誤的,我應該用什么呢?
關于我現在處理大多數事情的一個迷你例子是:
@Service("snippetService")
public class SnippetService {
@Autowired
private TestService testService;
public Snippet getSnippet() {
return testService.getSnippet();
}
}
是否使用自動裝配像這樣“錯了”還是我錯過了什么?
總結
以上是生活随笔為你收集整理的java的自动装配是什么意思_java – 什么时候在Spring中使用自动装配的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java动物飞翔接力赛源程序_java-
- 下一篇: mysql 交集_MYSQL交集函数