Results 1 to 3 of 3

Thread: Is it possible to have a "NotRequired" annotation?

  1. #1
    Join Date
    Aug 2008
    Posts
    2

    Question 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    What is wrong with

    Code:
    @Autowired(required=false)
    That would give the desired effect...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Aug 2008
    Posts
    2

    Default

    Quote 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 at 06:58 AM. Reason: added code tag

Tags for this Thread

Posting Permissions

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