Results 1 to 5 of 5

Thread: Preventing a bean from bean injected

  1. #1
    Join Date
    Dec 2005
    Location
    Edinburgh
    Posts
    6

    Default 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. #2

    Default

    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?

  3. #3
    Join Date
    Dec 2005
    Location
    Edinburgh
    Posts
    6

    Default

    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

  4. #4
    Join Date
    Aug 2006
    Location
    Now Germany, previously Ukraine
    Posts
    1,546

    Default

    Quote 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

  5. #5
    Join Date
    Sep 2006
    Location
    Hartford, CT
    Posts
    145

    Default

    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.
    Kent Rancourt
    DevOps Engineer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •