Struts Action get Resource by Injection

  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 

  "Q Ԓ Õf, Application Server> Q Ƿ Ô inject êPÄ Resource ϵ ½ y ֮ Ð, ԓ Application Server K>] ֧ Ԯ Struts Action û Framework, ͵ 춼 ʹ ϵ ½ y Ҳ Ú Java EE 5.0 ĭh Ј Ð ~ ~ Ҳ ʹ à JNDI lookup ȥ ȡ êPÄ Resource, 

  ÔO Ȼ ʹ 'TÄ Framework, Ͳ ޸ êP ԭ ʼ' a ȥ è Annotations. Ԓ Ҳ ҂

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags:

Releated Java Articles

Comments

Leave a Reply