Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which have more priority: Spring annotation or xml configuration

If i have a spring bean defined using both xml configuration and annotation. Then while initialization, which have more priority, xml or annotations.

Like my bean is...

package com.abc;    

@Component
Class Demo{
    ...
}

And my xml configuration is...

...
<context:annotation-config />
<context:component-scan base-package="com.abc" />

<bean id="demo" class="com.abc.Demo"/>
...

Now the demo bean is defined using both xml and annotations. While initialization, who is initializing bean: annotation or xml.

like image 451
user2550754 Avatar asked Nov 06 '25 05:11

user2550754


1 Answers

Annotation injection is performed before XML injection. Thus, the latter configuration will override the former for properties wired through both approaches.

like image 157
harryssuperman Avatar answered Nov 07 '25 19:11

harryssuperman