Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Default Spring Autowiring

 
Jayesh Pokar
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am new to Spring framework......

I want to know by default which auto-wiring way will be used to inject properties value to the class.

As I read I came to know that there is no default autowiring available, so how it is getting autowired in the below case where I didn't mention anything for autowiring.

beans.xml file

<bean id="javaLanguage" class="LanguageBean">
<property name="languageName" value="Java"/>
</bean>

LanguageBean.java

public class LanguageBean implements BeanNameAware
{
private String languageName;
private String beanName;

setter & getter are there.

}

When I run the Program i got the value for property name languageName, So by which mechanism it get injected the value, how it came to know to use setter injection and not constructor injection?
Also is Dependency Injection same as Autowiring?
Please help me.

Thanks.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the <property name=""> tag means call the set method using the name attribute. So <property name="hello" value="bonjour"/>

means call the setHello method passing in the String "bonjour"

For a constructor you use the <constructor-arg value="bonjour" passes in the String "bonjour" to a constructor.

Hope that helps

Mark>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic