在服務層獲取servlet上下文的最佳做法是什麼?在ServiceLayer中獲取ServletContext
0
A
回答
3
有許多選項,所有的人都錯了:
放在一個
ThreadLocal
(即每個請求),並通過ThreadLocalServletContextHolder.get()
把它作爲一個參數來得到它服務方法
它們是錯誤的,因爲服務層不應該知道它是提供數據的servlet。明天它可能會擺動。
所以正確的方法是收集servlet(或控制器)中的所有必需參數,並將它們作爲參數傳遞給服務層。一個更糟糕的選擇,但仍然沒有那麼差是得到Map
的屬性,並通過它。
+0
謝謝,我會通過我的要求的對象作爲argumnet – Zeeshan 2010-06-22 11:46:37
相關問題
- 1. 在JAX-RS資源中獲取ServletContext
- 2. 如何從AsyncContext獲取ServletContext?
- 3. 獲取ServletContext連接到JSP
- 4. Seam 2,如何獲取servletcontext?
- 5. ZF1-Doctrine2-ServiceLayer
- 6. ServiceLayer或Controller?
- 7. 從攔截器的MessageContext獲取ServletContext
- 8. 春季獲取工廠類的servletcontext
- 9. 在控制器中獲取ServletContext屬性「javax.servlet.context.tmpdir」
- 10. 如何獲取ServletContext中的ring init函數
- 11. 如何獲取其餘Web服務中的ServletContext
- 12. 的Struts 2:獲取在工廠類ServletContext的
- 13. Grails中的servletContext在哪裏?
- 14. 將PrivateKey存儲在ServletContext中
- 15. 在ServletListener中使用ServletContext
- 16. 如何獲取MEF目錄編目,查看Servicelayer和DAL的相同目錄?
- 17. @Service中的@Autowired ServletContext
- 18. ServletContext getContextPath()
- 19. 爲什麼我需要一個HttpSession來獲取ServletContext?
- 20. 從JSP頁面上的ServletContext獲取屬性
- 21. 當從ServletContext獲取真實路徑時發生NullPointerException
- 22. 使用Websockets時,無法在Spring Controller中獲得ServletContext
- 23. ServiceLayer Facade的外觀應該如何?
- 24. ServiceStack作爲ServiceLayer的MVC,WPF,WP7-8
- 25. 單元測試ServiceLayer與lambda和Moq
- 26. Java:在普通Java中等價的ServletContext
- 27. 可能存儲一個HashMap在ServletContext中?
- 28. ServletContext#getRealPath(File.separator)在tomcat中爲null
- 29. 如何在Spring中創建ServletContext
- 30. 獲取Config.groovy中的ServletContext(或如何獲取當前上下文的真實路徑)
最好的做法是'不要這樣做' - 服務層應該不知道客戶端應用程序的實現細節和協議。 – mjn 2010-06-22 10:07:46
無論您從ServletContext需要什麼,您都需要事先將其提取出來,並將* *完全傳遞給服務層。 – BalusC 2010-06-22 11:37:07
謝謝,我會通過我的要求的對象作爲argumnet – Zeeshan 2010-06-22 12:06:41