原创 Struts Action get Resource by Injection收藏

新一篇: JasperForge 正式開張 | 旧一篇: @Interceptors and inv.proceed()

http://www.codecomments.com/archive419-2006-6-954408.html

Craig McClanahan:

A couple of possibilities come to mind ...

* Inject the resource into a container-instantiated object (like a servlet), and modify your framework to copy values in when it creates, say, an Action instance in the Struts case. BIG PROBLEM: thread safety ... the servlet instance is shared across all threads, so the variable would get stomped on if there was more than one simultaneous request.

* Modify your framework to scan for the injection annotations itself when it creates new object instances, and perform the same kinds of injection that the container can do.

* Use a dependency injection framework that knows how to initialize properties from JNDI lookups, and configure it to look up the corresponding resources.

* Use the managed beans portion of JSF (even if you are not using the rest of it) as a dependency injection framework, and let the container go ahead and do the injection for you. (If you're using an additional framework, it would need to be modified to use managed beans to create object instances, instead of doing
Class.newInstance() things itself).

Craig



換句話說, Application Server 決定了是否可以 inject 相關的 Resource 到你的系統之中,如果該 Application Server 並沒有支援 Struts Action 或其他 Framework,就等於即使你的系統也在 Java EE 5.0 的環境中執行 ~~也得使用 JNDI lookup 去取得相關的 Resource,

假設仍然使用習慣的 Framework, 就不會修改相關原始碼去掃描 Annotations.應該也不會另外找個 DI Framework 來增加 Framework 的複雜度吧.. 難道 大家都得因為 ManagedBean support Injection 要被迫學習 JSF ?!

看來.. 在 Web-tier 利用 InjectionFilter or InjectionInitServlet 先取得相關資源,例如 DataSources, EntityManager 放到 SessionScope 或 ApplicationScope ?應該是比較可行的方案了.. 

 

 

发表于 @ 2006年07月18日 12:22:00|评论(loading...)|编辑

新一篇: JasperForge 正式開張 | 旧一篇: @Interceptors and inv.proceed()

评论

#SB 发表于2006-07-19 10:05:00  IP: 220.207.223.*
李日贵,怎么这名字就是那么....,你是日本人吗,SB
#操你妈 发表于2006-10-21 08:02:00  IP: 58.62.118.*
日本猪日的台湾狗!
#CNM 发表于2006-10-21 08:03:00  IP: 58.62.118.*
日本猪日的台湾狗!
#phpxer 发表于2006-10-25 14:25:00  IP: 203.86.43.*
啊,不好意思,有几个不礼貌的人骂你了,不要管他们。
发表评论  


当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
Csdn Blog version 3.1a
Copyright © jakarta99