示例#1
0
 public static void main(String[] args) {
   LOGGER.info("Starting ...");
   AnnotationConfigApplicationContext ctx =
       new AnnotationConfigApplicationContext(AppConfig.class);
   DemoService service = (DemoService) ctx.getBean("DemoService");
   service.doSomethig();
   ctx.registerShutdownHook();
 }
示例#2
0
  public static void main(String[] args) throws Throwable {

    String pkgName = AnimalFarmConfig.class.getPackage().getName();
    AnnotationConfigApplicationContext annotationConfigApplicationContext =
        new AnnotationConfigApplicationContext(pkgName);

    Cat cat = annotationConfigApplicationContext.getBean(Cat.class);
    cat.meow();

    Dog dog = annotationConfigApplicationContext.getBean(Dog.class);
    dog.bark();

    annotationConfigApplicationContext.registerShutdownHook();

    Pintor pintor = annotationConfigApplicationContext.getBean(Pintor.class);
    pintor.caminar();
  }
 @Override
 public void registerShutdownHook() {
   super.registerShutdownHook();
   this.registeredShutdownHook = true;
 }