Spring Tutorial 19 - The Autowired Annotation

preview_player
Показать описание
In this tutorial, we'll use the Autowired annotation to wire up dependencies. We'll learn how to add dependencies by type and name. We'll also use Qualifiers to narrow down dependency contenders.
Рекомендации по теме
Комментарии
Автор

Thanks Koushik!! I have watched your 20 videos till now and I am so impressed with you. May God bless you!!

nehaagrawal
Автор

All the spring tutorials I am following & its very useful for new learners like me.Thanks a lot Kaushik for creating & uploading such a clean & easy to understand videos. :)

kanchankulkarni
Автор

Very easy to understand, Thank you very much Koushik🙂

logeshbalaji
Автор

if you still get the then add <context:annotation-config/> to your xml config.

Neran
Автор

@koushik, I really appreciate the hard work and effort you have put into creating these videos. You are surely getting my blessings and thanks and I am sure from so many other fortunate as well.
One more request from your, I am sure very busy, schedule, can you also provide tutorials of Spring MVC ?
Thanks again.
AJ

CryptoJaat
Автор

You can use aliases. Add this line to the spring.xml file:
<alias name="pointA" alias="center" />

Chmilou
Автор

I use following xml configuration code and it works.

<?xml version="1.0" encoding="UTF-8"?>


   <context:annotation-config/>
 
    <bean id="pointA"
    <qualifier value="circleRelated" />
        <property name="x" value="0" />
        <property name="y" value="0" />
    </bean>
    <bean id="pointB"
        <property name="x" value="20" />
        <property name="y" value="0" />
    </bean>
    <bean id="pointC"
        <property name="x" value="-20" />
        <property name="y" value="0" />
    </bean>


<bean id="circle" >
    </bean>
    <bean />

</beans>

shuyiyang
Автор

Please make you videos on new version of spring

aashishganesh
Автор

sound of this expensive bike or car always catches my attention :D

chhayasharma
Автор

For people with error: (expected single matching bean but found 3 (or 4): ... ), update your pom.xml with this:

<dependency>


<version>2.5.6</version>
</dependency>
for:
<dependency>



</dependency>

<dependency>



</dependency>

notice the

(spring-core in <artifactId>)

and

(spring-context in <artifactId>)


willhdq
Автор

First point: add<context:annotation-config /> in your xml; second point: just link Bean name instead of <qualifier> field will work

linchenSeth
Автор

If you are getting the IllegalArgumentException after adding the <content:annotation-config/> then upgrade your version of spring to the latest one / one which is compatible with your JDK

JamesSapphire
Автор

Awesome:)Well presented/summarized from spring io docs:)I 'm kind of lazy who don't read the whole documentation.But you made it so simple and tried max to cover from docs

kumudamv
Автор

Hi Koushik, Thank you for these great tutorials. I have notice some thing when I follow your tutorial. It looks like is actually matching the parameter name instead of the member variable name. 
changing the member variable to a different name actually runs without any problem. even changing the setter method name runs without any problem. Only when I change the parameter name it actually throws the exception.
to illustrate. 

in xml file
<bean id="centre" class="com.banu.spring.Point" scope="prototype">
<property name="x" value="${pointA.x}" />
<property name="y" value="${pointA.y}" />
</bean>

<bean id="circle" >
</bean>

in Code Cicle.java
changing the member variable name from circle to circle1 did not break the program. 
I went ahead and change the setter as well 
public void setCentre1(Point centre) // not "1" prefixed But still the program runs
only when I change the parameter name it failed
public void setCentre(Point centre1) // look at the parameter name is centre1, this time I got the BeanCreationException.
I was expecting the exception in the previous cases (when member variable name didn't match or the setter Method name didn't match).

I am using spring Version 4.1.3

BanuKones
Автор

I get this error:  Could not autowire method: public void nested exception is No qualifying bean of type [com.mypackage.Point] is defined: expected single matching bean but found 3: pointA, pointB, pointC. I have to set Primary bean in the xml in order to make to work... I still want to know why qualifier is not working....

rjiang
Автор

Hello all, I was getting the error - the @Qualifier annotation is disallowed in this location. I was unable to locate the fix to this error after intensive search.
I was using all .jar files below 3.0 version. After changing the jar files to 3.0 and above version, the error got fixed. Hope this would be helpful to anyone out there facing this issue.

manasa
Автор

Hello I get a TypeMismatchException setting the centre of the Circle if I keep

<property name="y" value="${pointA.pointY}" />
Instead of
<property name="x" value="0" />

Before @Autowire the property file was working fine.

ТрендафилТанков
Автор

Hi everyone,
I have a problem. Everytime I paste <context:annotation-config/> to my xml file, the is thrown. My code doesn't throw an exception without <context:annotation-config/> but then I can't use annotations.

pabloaimar
Автор

is autowire annotation work when we are initializing the IOC container with Beanfacory interface?. like
BeanFactory apc=new XmlBeanFactory(new
in my case it only working with applicationcontaxt implementation.

Santoshchaa
Автор

How to find namespaces if you haven't added JARS manually but using maven?

raman-jnyt