Skip to content

Commit

Permalink
evolve(annotation): java source code as configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
chengcyber committed Dec 27, 2017
1 parent d17bded commit f06630d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
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();

}

}
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 {

}

0 comments on commit f06630d

Please sign in to comment.