dependency injection - What is the advantage of autowiring in spring -


what advantages of autowiring spring?

an example of autowiring in spring like

public class testclass {     testmethod() {         // .....     }; }  public class mainclass {     public static void main(string[] args) {         applicationcontext ctx = new classpathxmlapplicationcontext("test.xml");         testmethod obj = (testclass) ctx.getbean("test");         obj.testmethod();     } } 

test.xml

<bean id="test" class="testclass"> 

same in normal operation done using:

public class mainclass {     public static void main(string[] args) {         testclass obj = new testclass();         obj.testmethod();     }  } 

what advantage of spring, mean have heard terms inversion of control , dependency injection. in both examples reference of testclass used once through spring xml again through new oerator. can in simple terms explain advantage.

autowiring in spring autowiring feature of spring framework enables inject object dependency implicitly. internally uses setter or constructor injection. autowiring can't used inject primitive , string values. works reference only.

advantage of autowiring requires less code because don't need write code inject dependency explicitly.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -