Search code examples
javaspringspring-mvcapplicationcontext

How to activate JSR-250 annotation into a Spring application that is not configured using the XML configuration file?


I know that if I want use the JSR-250 annotations inside a Spring application configured by XML configuration file I have to put this tag inside the XML configuration file:

<context:annotation-config/>

But what I need to do to activate the JSR-250 annotations if I am using a Java configuration class or the annotations config instead the XML based configuration for my application?


Solution

  • The equivalent to <context:annotation-config/> is @AnnotationDrivenConfig:

    @Configuration
    @AnnotationDrivenConfig
    public class Config {
        // may now use @Autowired to reference beans from other @Configuration classes, XML, etc
    }