difference between autowire by name and bytype in spring

1
Difference between autowire byName and byType in Spring Spring framework provides the way to inject the bean dependencies using the autowire functionality. By default autowire functionality is disabled in spring framework. A developer explicitly define the autowiring configuration in spring configuration xml file. And this point is to remember that autowiring is only supported for object dependencies. The difference between byType and byName autowiring is as follows : 1 Autowire byType will search for a bean in configuration file, whose id match with the property type to be wired whereas autowire byName will search for a bean whose id is matching with the property name to be wired. 2 As a syntax wise difference is as follows: 3 package com.evon; 4 public class Company { private Employee emp; public String setEmp(Employee emp) { this .emp = emp; } } To view full blog about Difference between autowire byName and byType in Spring visit FindNerd. You can also read such more blogs at our Java Development Blogs section. You can also ask question related to Java at our Java developer forum .

Upload: findnerd

Post on 17-Aug-2015

16 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Difference between autowire by name and bytype in spring

Difference between autowire byName and byType in Spring

Spring framework provides the way to inject the bean dependencies using the autowire functionality. By default autowire functionality is disabled in spring framework. A developer explicitly define the autowiring configuration in spring configuration xml file. And this point is to remember that autowiring is only supported for object dependencies.

The difference between byType and byName autowiring is as follows :

1 Autowire byType will search for a bean in configuration file, whose id match with the property type to be wired whereas autowire byName will search for a bean whose id is matching with the property name to be wired.

2 As a syntax wise difference is as follows:

3 package com.evon;

4 public class Company { private Employee emp; public String setEmp(Employee emp) { this .emp = emp; } }

To view full blog about Difference between autowire byName and byType in Spring visit FindNerd.

You can also read such more blogs at our Java Development Blogs section.

You can also ask question related to Java at our Java developer forum.