-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
evolve(annotation): java source code as configuration
- Loading branch information
1 parent
d17bded
commit f06630d
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
spring-demo-annotations/src/com/luv2code/springdemo/JavaConfigDemoApp.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.luv2code.springdemo; | ||
|
||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
|
||
public class JavaConfigDemoApp { | ||
|
||
public static void main(String[] args) { | ||
|
||
// read spring config java class | ||
AnnotationConfigApplicationContext ctx = | ||
new AnnotationConfigApplicationContext(SportConfig.class); | ||
|
||
// get the bean from spring container | ||
TennisCoach theCoach = ctx.getBean("tennisCoach", TennisCoach.class); | ||
|
||
// call a method on the bean | ||
System.out.println(theCoach.getDailyWorkout()); | ||
|
||
// call a method with dependency injection | ||
System.out.println(theCoach.getDailyFortune()); | ||
|
||
// call getter methods with literal value injection | ||
System.out.println(theCoach.getEmail()); | ||
System.out.println(theCoach.getTeam()); | ||
|
||
|
||
// close the context | ||
ctx.close(); | ||
|
||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
spring-demo-annotations/src/com/luv2code/springdemo/SportConfig.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.luv2code.springdemo; | ||
|
||
|
||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@ComponentScan("com.luv2code.springdemo") | ||
public class SportConfig { | ||
|
||
} |