Skip to content

Commit

Permalink
add a bean and indentation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fishercoder1534 committed Jan 20, 2024
1 parent b2f9ba8 commit 3cdc8b1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
21 changes: 12 additions & 9 deletions src/main/java/spring_component_scan_example/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**This app is running fine! It helps me understand how component scan works! Cool!
* Look at this project along with other two:
/**
* This app is running fine! It helps me understand how component scan works! Cool!
* Look at this project along with other two:
* Spring@ResourceAnnotationExample
* SpringComponentScanExample
* to help me better understand the three possible ways to do DI using Spring.*/
* to help me better understand the three possible ways to do DI using Spring.
*/

public class MainApp {

public static void main(String... args) {
AbstractApplicationContext context = new ClassPathXmlApplicationContext("spring_component_scan_example.xml");
Person p =(Person) context.getBean("person");
AbstractApplicationContext context = new ClassPathXmlApplicationContext("spring_component_scan_example.xml");
Person p = (Person) context.getBean("person");

System.out.println(p.getCity().toString());
System.out.println(p.getWife().toString());
System.out.println(p.getCareer().toString());
}
System.out.println(p.getCity().toString());
System.out.println(p.getWife().toString());
System.out.println(p.getCareer().toString());
System.out.println("Program finished.");
}
}
8 changes: 7 additions & 1 deletion src/main/resources/spring_component_scan_example.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--suppress SpringFacetInspection -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
Expand All @@ -13,6 +14,11 @@ It does a component scan for this package, so any beans that have any one of the
will be scanned and autowired up.
Also I'll have to put @Autowired annotation on those private fields inside that Person clalss. -->

<context:component-scan base-package="spring_component_scan_example"/>
<context:component-scan base-package="spring_component_scan_example"/>

<bean id="wife" class="spring_component_scan_example.Wife">
<property name="name" value="Sophie Sun"/>
<property name="faith" value="Christian"/>
</bean>

</beans>

0 comments on commit 3cdc8b1

Please sign in to comment.