File tree Expand file tree Collapse file tree
telusko/Spring/third-spring-frmaework/src/main
java/org/akash/learn/spring Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,8 +12,8 @@ public static void main(String[] args) {
1212 System .out .println ("In main method" );
1313 System .out .println (Arrays .toString (names ));
1414
15- Dev obj = ( Dev ) context .getBean ("dev" );
16- System .out .println (obj .getAge ());
15+ Dev obj = context .getBean (Dev . class );
16+ // System.out.println(obj.getAge());
1717 obj .learn ();
1818 }
1919}
Original file line number Diff line number Diff line change 1+ package org .akash .learn .spring ;
2+
3+ public interface Computer {
4+ void compile ();
5+ }
Original file line number Diff line number Diff line change 1+ package org .akash .learn .spring ;
2+
3+ public class Desktop implements Computer {
4+ @ Override
5+ public void compile (){
6+ System .out .println ("Compiling in Desktop" );
7+ }
8+ }
Original file line number Diff line number Diff line change 11package org .akash .learn .spring ;
22
3- import org .springframework .stereotype .Component ;
4-
53public class Dev
64{
7- private Laptop laptop ;
8- private int age ;
5+ private Computer computer ;
6+ // private int age;
97
108// public Dev(int age) {
119// this.age = age;
1210// }
1311
1412
15- public Dev (int age , Laptop laptop ) {
16- this .age = age ;
17- this .laptop = laptop ;
18- }
19-
20- public Laptop getLaptop () {
21- return laptop ;
22- }
13+ // public Dev(int age, Laptop laptop) {
14+ // this.age = age;
15+ // this.laptop = laptop;
16+ // }
2317
24- public void setLaptop ( Laptop laptop ) {
25- this . laptop = laptop ;
18+ public Computer getComputer ( ) {
19+ return computer ;
2620 }
2721
28- public int getAge ( ) {
29- return age ;
22+ public void setComputer ( Computer computer ) {
23+ this . computer = computer ;
3024 }
3125
32- public void setAge (int age ) {
33- this .age = age ;
34- }
26+ // public int getAge() {
27+ // return age;
28+ // }
29+ //
30+ // public void setAge(int age) {
31+ // this.age = age;
32+ // }
3533
3634 public void learn (){
3735 System .out .println ("Learning Spring Boot" );
38- laptop .compile ();
36+ computer .compile ();
3937 }
4038}
Original file line number Diff line number Diff line change 11package org .akash .learn .spring ;
22
3- public class Laptop {
3+ public class Laptop implements Computer {
4+ @ Override
45 public void compile (){
5- System .out .println ("Compiling......... " );
6+ System .out .println ("Compiling in Laptop " );
67 }
78}
Original file line number Diff line number Diff line change 33 xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
44 xsi : schemaLocation ="
55 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" >
6- <bean id =" dev" class =" org.akash.learn.spring.Dev" >
6+ <bean id =" dev" class =" org.akash.learn.spring.Dev" autowire = " byType " >
77<!-- setter injection-->
88<!-- <property name="age" value="12"/>-->
99<!-- constructor injection-->
1010<!-- <constructor-arg value="14"/>-->
1111<!-- <property name="laptop" ref="laptop"/>-->
12- <constructor-arg index =" 0" value =" 12" />
13- <constructor-arg index =" 1" ref =" laptop" />
12+ <!-- <constructor-arg index="0" value="12"/>-->
13+ <!-- <constructor-arg index="1" ref="laptop"/>-->
14+ <!-- <property name="computer" ref="desktop" />-->
1415 </bean >
15- <bean id =" laptop" class =" org.akash.learn.spring.Laptop" >
16+ <bean id =" laptop" class =" org.akash.learn.spring.Laptop" primary =" true" >
17+ </bean >
18+ <bean id =" desktop" class =" org.akash.learn.spring.Desktop" >
1619 </bean >
1720</beans >
You can’t perform that action at this time.
0 commit comments