Last active
August 29, 2015 14:10
-
-
Save michalkowol/360bab621fa243e67894 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <beans xmlns="http://www.springframework.org/schema/beans" | |
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> | |
| <bean id="apple" class="Apple" /> | |
| <bean id="juicer" class="Juicer"> | |
| <constructor-arg ref="apple" /> | |
| <constructor-arg ref="peeler" /> | |
| </bean> | |
| <bean id="peeler" class="Peeler"> | |
| <constructor-arg ref="apple" /> | |
| </bean> | |
| </beans> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- ... --> | |
| <bean id="juicer" class="Juicer" scope="prototype"> | |
| <!-- ... --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface Fruit { | |
| void eat(); | |
| String getName(); | |
| } | |
| public interface Peelable { | |
| void peel(); | |
| } | |
| public class Apple implements Fruit, Peelable { | |
| public void peel() { } | |
| public void eat() { } | |
| String getName() { return "apple"; } | |
| } | |
| public class Peeler { | |
| private final Peelable peelable; | |
| public Peeler(Peelable peelable) { | |
| this.peelable = peelable; | |
| } | |
| } | |
| public class Juicer { | |
| private final Peelable peelable; | |
| private final Peeler peeler; | |
| public Juicer(Peelable peelable, Peeler peeler) { | |
| this.peelable = peelable; | |
| this.peeler = peeler; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MainAppPrototype { | |
| public static void main(String[] args) { | |
| ApplicationContext context = new ClassPathXmlApplicationContext("beans_prototype.xml"); | |
| Juicer j1 = context.getBean(Juicer.class); | |
| Juicer j2 = context.getBean(Juicer.class); | |
| System.out.println(j1 == j2); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MainAppSingleton { | |
| public static void main(String[] args) { | |
| ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); | |
| Juicer j1 = context.getBean(Juicer.class); | |
| Juicer j2 = context.getBean(Juicer.class); | |
| System.out.println(j1 == j2); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment