How to enable @Required?

How to enable @Required annotation in Java (Spring 3.1)? Not in xml, but through Java. Also under this annotation did I enable this feature? In the @Feature section (in @FutureConfiguration or @ Bean (in @Configuration)?

Edit:

    @Feature
    public MvcAnnotationDriven annotationDriven(ConversionService conversionService) {
        return new MvcAnnotationDriven().conversionService(conversionService)
                .argumentResolvers(new CustomArgumentResolver());
    }

Does this include all annotations?

+3
source share
3 answers

The answer to @anubhava works, but it refers to the Spring 2.0 manual, which is 5 years old.

In the configuration XML Spring 3.x has a more elegant approach <context:annotation-config/>. It also provided a whole set of functions that you are likely to need, while RequiredAnnotationBeanPostProcessoronly a few allow.

See Spring 3.x manual .

@Bean -style, , @Required, , @Bean. , - Spring 3.1 -, , , .

, , 3.0.x.

+5

Spring:

(, ) Spring, "" . "setter" , . , @Required .

RequiredAnnotationBeanPostProcessor . BeanPostProcessor, @ "", ". ; bean XML- Spring.

<bean class=
"org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/>

, : http://static.springsource.org/spring/docs/2.0.x/reference/metadata.html

+2

AnnotationConfigApplicationContext, XML:

, - , @Configuration - , @Components , JSR-330, javax.inject . (register(java.lang.Class...)), (scan(java.lang.String...)).

, Bean, , . bean .

:

ConfigurableApplicationContext applicationContext =
new AnnotationConfigApplicationContext(
    "com.mycompany.package1",
    "com.mycompany.package2",
    "com.mycompany.package3"
    // etc.
);
applicationContext.refresh();
0

All Articles