Announcement Announcement Module
Collapse
No announcement yet.
Is it possible to have a "NotRequired" annotation? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is it possible to have a "NotRequired" annotation?

    Hello everyone. I'm relatively new to Spring, and my question is this: Is it possible to have the reverse semantics of the "Required" annotation? That is, I would like to enforce all dependencies to be set throughout my project unless if a setter is marked with something like e.g. "NotRequired" or "Optional". After looking at the manual I am under the impression that this is not supported. Still, I would appreciate some advice on what would be the best way to do it. Will I have to put in some custom logic in my code or is there a better way?

    thanks,
    Alex

  • #2
    What is wrong with

    Code:
    @Autowired(required=false)
    That would give the desired effect...

    Comment


    • #3
      Originally posted by Marten Deinum View Post
      What is wrong with

      Code:
      @Autowired(required=false)
      That would give the desired effect...
      Thanks, but I should have mentioned that I'm trying to use an already-existing annotation with spring.
      Code:
      public @interface Parameter {
          boolean required() default true;
      }
      I was thinking that maybe I could implement a custom PostProcessor to replace RequiredAnnotationBeanPostProcessor. Would this be an option?
      Last edited by alex.g; Aug 1st, 2008, 06:58 AM. Reason: added code tag

      Comment

      Working...
      X