Table of Contents
This is 15 of 16 parts of tutorial series
Tutorial Content: Spring tutorial for beginners
- Introduction to spring framework
- Spring interview questions
- Dependency injection(ioc) in spring
- Spring XML based configuration example
- Spring java based configuaration
- Dependency injection via setter method in spring
- Dependency injection via constructor in spring
- Spring Bean scopes with examples
- Initializing collections in spring
- Beans Autowiring in spring
- Inheritance in Spring
- Spring ApplicationContext
- Spring lifetime callbacks
- BeanPostProcessors in Spring
- Annotation based Configuration in spring
- Spring AOP tutorial
There are two ways via which you can inject dependency in spring
- By configuring XML.
- By using annotation.
In all our previous posts,we have injected dependency by configuring XML file but instead of doing this,we can move the bean configuration into the component class itself by using annotations on the relevant class, method, or field declaration.
You might think what if you have done both i.e.used annotations and XML both.In that case,XML configuration will override annotations because XML configuration will be injected after annotations.
Now annotations based configuration is turned off by default so you have to turn it on by entering into spring XML file.
ApplicationContext.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:annotation-config/> <!-- beans declaration goes here --> </beans> |
thank you so much for your tutoriel, can you add an example for annotations ?
Nice tutorial 🙂 (y)
Dharmendra: Link is not working
Hey guys the link is not working…
Here is the new link http://techieme.in/annotation-based-spring-mvc/
awesome tutorial with useful working examples. thx for the great work! I learn Spring solely from these example.
My stride up perfect step on Java+Spring, thanks alot!
need examples
You are a true servant to us Programmers! Thank you soo much.
Thanks, Very good tutorial.
Are there posts for Sprint MVC as well.
finally i learned the basics of Spring 🙂 in just a day! thanks for this very comprehensive tutorials 🙂 though i was hoping you'd have an example for the annotation based configurations.