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

  • Preventing a bean from bean injected

    I want to prevent a particular bean from being 'injectable', but need Spring to do everything else as per usual.

    I am trying to enforce all access to a Spring bean to be via a singleton, so I can perform concurrency control. (I may NOT use AOP.)

    I cannot seem to find any documentation indicating that I can do this.

  • #2
    So create a singleton design patterened class and use it in your code. Why do you feel you need to have the bean in the .xml if you don't want it to be injected?

    Comment


    • #3
      The bean itself needs a number of Spring services: JMX exportation, Spring's eventing mechanism and needs a number of beans injected into it. For all intents and purposes it is a Spring bean, that is part of a Spring managed hierarchy but has a few border-case requirements that is forcing me to consider this solution pattern.

      Thanks

      Comment


      • #4
        Originally posted by ajls View Post
        I want to prevent a particular bean from being 'injectable', but need Spring to do everything else as per usual.

        I am trying to enforce all access to a Spring bean to be via a singleton, so I can perform concurrency control. (I may NOT use AOP.)

        I cannot seem to find any documentation indicating that I can do this.
        Nothing can prevent been from explicit injection. To prevent been from injection by autowaring specify autowire-candidate="false" on bean definition (see chapter 3.3.5.1 in Spring 2.5.1 Reference).

        Regards,
        Oleksandr

        Comment


        • #5
          Can you elaborate on what you mean by not wanting the bean to be "injectable?"

          Does that mean that you don't want anything injected into said bean? Or does it mean you don't want said bean being injected into other beans?

          Can you provide a more concrete example of how you'd like the finished result to behave. Depending on your answers, I may have some very simple recommendations.

          Also, regarding the restriction on AOP, may I ask for more detail around that? I know what it's like to work at a large company that is paranoid about new technology. Indeed, in my own case, use of AspectJ is not allowed because as a company we seem to be paranoid about byte-weaving. We do however allow AOP Alliance style AOP where proxies are generated dynamically at runtime using reflection. Is there any chance that you can get away with that??? Spring has great support for both styles of AOP.

          Comment

          Working...
          X