Package org.springframework.context.annotation

Examples of org.springframework.context.annotation.AnnotationConfigApplicationContext


 
  public static void main(String[] args)
  {
    PropertyConfigurator.configure(System
        .getProperty("log4j.configuration"));
    AbstractApplicationContext ctx = new AnnotationConfigApplicationContext(ZombieSpringConfig.class);
    // For the destroy method to work.
    ctx.registerShutdownHook();
   
    // Start the main game server
    ServerManager serverManager = ctx.getBean(ServerManager.class);
    //serverManager.startServers(18090,843,8081);
    try
    {
      serverManager.startServers();
    }
View Full Code Here


  private static final Logger LOG = LoggerFactory.getLogger(SpringNettyServer.class);
  public static void main(String[] args)
  {
    PropertyConfigurator.configure(System
        .getProperty("log4j.configuration"));
    AbstractApplicationContext context = new AnnotationConfigApplicationContext(JetServerSpringConfig.class);
   
    // For the destroy method to work.
    context.registerShutdownHook();
   
    // Start tcp and flash servers
    ServerManager manager = (ServerManager)context.getBean("serverManager");
    try
    {
      manager.startServers(8090,843,8081);
    }
    catch (Exception e)
View Full Code Here

    public ApplicationContext loadContext(String... locations) {
        if (logger.isDebugEnabled()) {
            logger.debug("Creating a JavaConfigApplicationContext for " + Arrays.asList(locations));
        }

        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

        ArrayList<Class<?>> configClasses = new ArrayList<Class<?>>();
        ArrayList<String> basePackages = new ArrayList<String>();
        for (String location : locations) {
            // if the location refers to a class, use it. Otherwise assume it's a base package name
            try {
                final Class<?> aClass = this.getClass().getClassLoader().loadClass(location);
                configClasses.add(aClass);
            } catch (ClassNotFoundException e) {
                if (Package.getPackage(location) == null) {
                    throw new IllegalArgumentException(
                            String.format("A non-existent class or package name was specified: [%s]", location));
                }
                basePackages.add(location);
            }
        }

        if (logger.isDebugEnabled()) {
            logger.debug("Setting config classes to " + configClasses);
            logger.debug("Setting base packages to " + basePackages);
        }

        for (Class<?> configClass : configClasses) {
            context.register(configClass);
        }
       
        for (String basePackage : basePackages) {
            context.scan(basePackage);
        }
       
        context.refresh();

        // Have to create a child context that implements BeanDefinitionRegistry
        // to pass to registerAnnotationConfigProcessors, since
        // JavaConfigApplicationContext does not
        final GenericApplicationContext gac = new GenericApplicationContext(context);
        AnnotationConfigUtils.registerAnnotationConfigProcessors(gac);
        // copy BeanPostProcessors to the child context
        for (String bppName : context.getBeanFactory().getBeanNamesForType(BeanPostProcessor.class)) {
            gac.registerBeanDefinition(bppName, context.getBeanFactory().getBeanDefinition(bppName));
        }
        gac.refresh();
        gac.registerShutdownHook();

        return gac;
View Full Code Here

    public ApplicationContext loadContext(String... locations) {
        if (logger.isDebugEnabled()) {
            logger.debug("Creating a JavaConfigApplicationContext for " + Arrays.asList(locations));
        }

        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

        ArrayList<Class<?>> configClasses = new ArrayList<Class<?>>();
        ArrayList<String> basePackages = new ArrayList<String>();
        for (String location : locations) {
            // if the location refers to a class, use it. Otherwise assume it's a base package name
            try {
                final Class<?> aClass = this.getClass().getClassLoader().loadClass(location);
                configClasses.add(aClass);
            } catch (ClassNotFoundException e) {
                if (Package.getPackage(location) == null) {
                    throw new IllegalArgumentException(
                            String.format("A non-existent class or package name was specified: [%s]", location));
                }
                basePackages.add(location);
            }
        }

        if (logger.isDebugEnabled()) {
            logger.debug("Setting config classes to " + configClasses);
            logger.debug("Setting base packages to " + basePackages);
        }

        for (Class<?> configClass : configClasses) {
            context.register(configClass);
        }
       
        for (String basePackage : basePackages) {
            context.scan(basePackage);
        }
       
        context.refresh();

        // Have to create a child context that implements BeanDefinitionRegistry
        // to pass to registerAnnotationConfigProcessors, since
        // JavaConfigApplicationContext does not
        final GenericApplicationContext gac = new GenericApplicationContext(context);
        AnnotationConfigUtils.registerAnnotationConfigProcessors(gac);
        // copy BeanPostProcessors to the child context
        for (String bppName : context.getBeanFactory().getBeanNamesForType(BeanPostProcessor.class)) {
            gac.registerBeanDefinition(bppName, context.getBeanFactory().getBeanDefinition(bppName));
        }
        gac.refresh();
        gac.registerShutdownHook();

        return gac;
View Full Code Here

      // 开始时
      public void contextStarting(ApplicationContext applicationContext,
          Bundle bundle) {
        if (AnnotationConfigApplicationContext.class
            .isInstance(applicationContext)) {
          AnnotationConfigApplicationContext annotationConfigApplicationContext = (AnnotationConfigApplicationContext) applicationContext;
          // 设置Bean名称生成器
          annotationConfigApplicationContext
              .setBeanNameGenerator(new MySpringBeanNameGenerator());
        }
      }

      // 开始后
View Full Code Here

    //  Extract component configuration classes available in System properties
    Class<?>[] configClasses = getComponentsToLoad();
    //  Configure via Spring DI using named Spring's Java Config magic.
    //  Multiple component configurations can be loaded into a Spring container.
    context =
      new AnnotationConfigApplicationContext(configClasses);
    //  Extract all Ducc components from Spring container
//    Map<String,AbstractDuccComponent> duccComponents =
    duccComponents =
      context.getBeansOfType(AbstractDuccComponent.class);
    //  Start all components
View Full Code Here

    public ApplicationContext loadContext(String... locations) {
        if (logger.isDebugEnabled()) {
            logger.debug("Creating a JavaConfigApplicationContext for {}", Arrays.asList(locations));
        }

        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

        List<Class<?>> configClasses = new ArrayList<Class<?>>();
        List<String> basePackages = new ArrayList<String>();
        for (String location : locations) {
            // if the location refers to a class, use it. Otherwise assume it's a base package name
            try {
                final Class<?> aClass = this.getClass().getClassLoader().loadClass(location);
                configClasses.add(aClass);
            } catch (ClassNotFoundException e) {
                if (Package.getPackage(location) == null) {
                    throw new IllegalArgumentException(
                            String.format("A non-existent class or package name was specified: [%s]", location));
                }
                basePackages.add(location);
            }
        }

        logger.debug("Setting config classes to {}", configClasses);
        logger.debug("Setting base packages to {}", basePackages);

        for (Class<?> configClass : configClasses) {
            context.register(configClass);
        }
       
        for (String basePackage : basePackages) {
            context.scan(basePackage);
        }
       
        context.refresh();

        // Have to create a child context that implements BeanDefinitionRegistry
        // to pass to registerAnnotationConfigProcessors, since
        // JavaConfigApplicationContext does not
        final GenericApplicationContext gac = new GenericApplicationContext(context);
        AnnotationConfigUtils.registerAnnotationConfigProcessors(gac);
        // copy BeanPostProcessors to the child context
        for (String bppName : context.getBeanFactory().getBeanNamesForType(BeanPostProcessor.class)) {
            gac.registerBeanDefinition(bppName, context.getBeanFactory().getBeanDefinition(bppName));
        }
        gac.refresh();
        gac.registerShutdownHook();

        return gac;
View Full Code Here

        return answer.toArray(new Class<?>[answer.size()]);
    }
       
    protected AbstractApplicationContext createDefaultApplicationContext() {
        ApplicationContext parentContext = getParentApplicationContext();
        AnnotationConfigApplicationContext acApplicationContext = new AnnotationConfigApplicationContext();
        if (parentContext != null) {
            acApplicationContext.setParent(parentContext);
        }
        if (getConfigClassesString() != null) {
            Class<?>[] configClasses = getConfigClasses(getConfigClassesString());
            for (Class<?> cls : configClasses) {
                acApplicationContext.register(cls);
            }
        }
        if (getBasedPackages() != null) {
            String[] basePackages = getBasedPackages().split(";");
            for (String basePackage : basePackages) {
                acApplicationContext.scan(basePackage);
            }
        }
        acApplicationContext.refresh();
        return acApplicationContext;
       
    }
View Full Code Here

    return new MessageService();
  }
 
  public static ApplicationContext getContext(){
    if(context == null)
      context = new AnnotationConfigApplicationContext(ApplicationConfiguration.class);
    return context;
  }
View Full Code Here

        return answer.toArray(new Class<?>[answer.size()]);
    }
       
    protected AbstractApplicationContext createDefaultApplicationContext() {
        ApplicationContext parentContext = getParentApplicationContext();
        AnnotationConfigApplicationContext acApplicationContext = new AnnotationConfigApplicationContext();
        if (parentContext != null) {
            acApplicationContext.setParent(parentContext);
        }
        if (getConfigClassesString() != null) {
            Class<?>[] configClasses = getConfigClasses(getConfigClassesString());
            for (Class<?> cls : configClasses) {
                acApplicationContext.register(cls);
            }
        }
        if (getBasedPackages() != null) {
            String[] basePackages = getBasedPackages().split(";");
            for (String basePackage : basePackages) {
                acApplicationContext.scan(basePackage);
            }
        }
        acApplicationContext.refresh();
        return acApplicationContext;
       
    }
View Full Code Here

TOP

Related Classes of org.springframework.context.annotation.AnnotationConfigApplicationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.