Spring @Autowired Annotation

Spring @Autowired annotation is used to automatically inject dependencies. Where to apply @Autowired annotation You can apply the @Autowired annotation to setter methods. See example. You can apply the @Autowired annotation to constructors. See example. You can apply @Autowired to fields. See example. You can also apply the annotation to…

Continue reading

Spring @Resource Annotation

For autowiring in Spring apart from using @Autowired annotation there is also support for JSR 330’s @Inject annotation and JSR-250 @Resource annotation. In this post we’ll see how to use Spring @Resource annotation for autowiring. @Resource annotation in Spring @Resource annotation can be used on fields or bean property setter…

Continue reading

Spring @Configuration Annotation

Spring @Configuration annotation helps in creating Java based configuration in Spring rather than relying on XML based configuration. Any class annotated with @Configuration indicates that a class declares one or more @Bean methods that are processed by the Spring container to generate bean definitions and manage the overall bean lifecycle.…

Continue reading

Spring @Required Annotation

Spring @Required annotation is used with a method, typically a setter method thus making setter dependency injection for that property mandatory. RequiredAnnotationBeanPostProcessor class Registering RequiredAnnotationBeanPostProcessor class is required to use @Required annotation. A default RequiredAnnotationBeanPostProcessor will be registered by the “context:annotation-config” and “context:component-scan” XML tags. Spring @Required annotation examples In…

Continue reading

Spring @Import Annotation

This post shows how to use @Import annotation in Spring. In an application you may have several bean definitions making your @Configuration class quite huge. Rather than putting all the bean definitions in a single configuration class you can break your configuration into several small configurations module wise. Then using…

Continue reading

Spring @Conditional Annotation

Using Spring @Conditional annotation you can conditionally register a component. With @Conditional annotation you need to specify a condition and the component is registered only if the condition is true. For specifying the condition you need to implement org.springframework.context.annotation.Condition interface. Where to use @Conditional annotation The @Conditional annotation may be…

Continue reading

Spring @Value Annotation

Spring @Value annotation at the field or method/constructor parameter level is used to inject a value. @Value annotation in Spring can be used in the following ways- Directly to inject a value at the field, method or constructor level. Using @Value annotation you can also assign a value by reading…

Continue reading

Spring Expression Language (SpEL) Tutorial

The Spring Expression Language (“SpEL”) is an expression language that supports querying and manipulating an object graph at runtime. In this post we’ll see examples of using SpEL with both XML and annotation based configuration. The expression language supports the following functionality: Literal expressions Boolean, relational and mathematical operators Regular…

Continue reading