Announcement Announcement Module
Collapse
No announcement yet.
Preventing access to beans from a contect Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Preventing access to beans from a contect

    Hi all,

    I have a bean named UserFacade. The application context defines the UserFacade and injects the UserBusinessLayer into the UserFacade which in turn injects UserDAO into the UserBusinessLayer.

    The initial lookup is done via the application context user the getBean method (getBean("userFacade"). How do I allow the web layer to retrieve the UserFacade only and not the other beans. In other works, the web layer should not be allowed to call getBean in order to retrieve the UserBusinessLayer and UserDAO bean objects.

    dino

  • #2
    dino,
    I do not know of a way to prevent a client code, that has a reference to a Spring context, to access this context non abstract beans.
    If you are using Spring MVC for your Web Layer, your can Inverse the Control and inject your facade bean into your controller.

    Comment


    • #3
      Do you mean "web layer" as in JSPs or the like, or web controllers? JSPs and other views should only access model objects exposed by the web tier, and should never have access to a Spring context. Web controllers should normally receive context objects using DI, and try to avoid lookups.

      If you are using Spring MVC for your Web Layer, your can Inverse the Control and inject your facade bean into your controller
      Yes, you want to avoid using getBean() at all if possible, and prefer a DI approach, which doesn't tie you to the Spring API.

      Comment

      Working...
      X