2018年11月10日 | Leave a comment package demo.core1; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.stereotype.Component; /** * * @author 老唐 */ public class App { /** * * @author 老唐 */ @Component public static class Bean1 { public String getMsg() { return "你好"; } } public static void main(String[] argv) { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext("demo.core1"); final Bean1 b1 = ctx.getBean(Bean1.class); System.out.print("b1.getMsg()" + b1.getMsg()); } } 1234567891011121314151617181920212223242526272829 package demo.core1; import org.springframework.context.annotation.AnnotationConfigApplicationContext;import org.springframework.stereotype.Component; /** * * @author 老唐 */public class App { /** * * @author 老唐 */ @Component public static class Bean1 { public String getMsg() { return "你好"; } } public static void main(String[] argv) { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext("demo.core1"); final Bean1 b1 = ctx.getBean(Bean1.class); System.out.print("b1.getMsg()" + b1.getMsg()); }}