Package org.springframework.context

Examples of org.springframework.context.ConfigurableApplicationContext


            return;
        }

        String[] beanNames = beanFactory.getBeanNamesForType(type);

        ConfigurableApplicationContext ctxt = (ConfigurableApplicationContext)beanFactory;

        // Take any bean name or alias that has a web service annotation
        for (int i = 0; i < beanNames.length; i++) {

            BeanDefinition def = ctxt.getBeanFactory().getBeanDefinition(beanNames[i]);

            if (!beanFactory.isSingleton(beanNames[i]) || def.isAbstract()) {
                continue;
            }

            try {
                Collection<?> ids = null;
                PropertyValue pv = def.getPropertyValues().getPropertyValue(idsProperty);
               
                if (pv != null) {
                    Object value = pv.getValue();
                    if (!(value instanceof Collection)) {
                        throw new RuntimeException("The property " + idsProperty + " must be a collection!");
                    }

                    if (value instanceof Mergeable) {
                        if (!((Mergeable)value).isMergeEnabled()) {
                            ids = (Collection<?>)value;
                        }
                    } else {
                        ids = (Collection<?>)value;
                    }
                }
                if (ids == null && staticFieldName != null) {
                    Class<?> cls = context.getType(beanNames[i]);
                    try {
                        final Field f = cls.getDeclaredField(staticFieldName);
                        ReflectionUtil.setAccessible(f);

                        Collection<QName> sids = CastUtils.cast((Collection<?>)f.get(null));
                        if (sids != null) {
                            ids = new ArrayList<QName>(sids);
                        }
                    } catch (Exception ex) {
                        //ignore, fall through
                    }
                }

                // if values are not legal keys (for lazy-init bean definitions id values may be
                // BeanDefinitionHolders), load the bean and get its id values instead
                // for BeanReference type values, simply resolve reference
                // 
                if (null != ids) {
                    Collection<Object> checked = new ArrayList<Object>(ids.size());
                    for (Object id : ids) {
                        if (id instanceof QName) {
                            checked.add(id);
                        } else if (id instanceof BeanReference) {
                            BeanReference br = (BeanReference)id;
                            Object refId = context.getBean(br.getBeanName());
                            checked.add(refId);
                        } else if (id instanceof BeanDefinitionHolder) {
                            BeanDefinitionHolder bdh = (BeanDefinitionHolder)id;
                            if (QName.class.getName().equals(bdh.getBeanDefinition().getBeanClassName())) {
                                try {
                                    java.util.List<ValueHolder> l
                                        = bdh.getBeanDefinition().getConstructorArgumentValues()
                                            .getGenericArgumentValues();
                                   
                                    ConstructorArgumentValues.ValueHolder v
                                        = l.get(0);
                                   
                                    TypedStringValue nss = (TypedStringValue)v.getValue();
                                    v = l.get(1);
                                    TypedStringValue ln = (TypedStringValue)v.getValue();
                                    checked.add(new QName(nss.getValue(), ln.getValue()));
                                } catch (Exception ex) {
                                    //ignore
                                    break;
                                }
                            } else {
                                break;
                            }
                        } else {
                           
                            break;
                        }
                    }
                    if (checked.size() < ids.size()) {
                        ids = null;
                    } else {
                        ids = checked;
                    }
                }
                if (ids == null) {
                    ids = getIds(ctxt.getBean(beanNames[i]));
                    if (ids == null) {
                        continue;
                    }
                }
               
                for (Object id : ids) {
                    QName key = (QName)id;
                    getBeanListForId(key).add(beanNames[i]);
                }
            } catch (BeanIsAbstractException e) {
                // The bean is abstract, we won't be doing anything with it.
                continue;
            }
        }

        processBeans(ctxt.getParent());
    }
View Full Code Here


     *
     * @param owner user or role
     * @param attrUtil attributable util
     */
    public void retrieveVirAttrValues(final AbstractAttributable owner, final AttributableUtil attrUtil) {
        final ConfigurableApplicationContext context = ApplicationContextProvider.getApplicationContext();
        final ConnectorFactory connFactory = context.getBean(ConnectorFactory.class);

        final IntMappingType type = attrUtil.getType() == AttributableType.USER
                ? IntMappingType.UserVirtualSchema : attrUtil.getType() == AttributableType.ROLE
                ? IntMappingType.RoleVirtualSchema : IntMappingType.MembershipVirtualSchema;

View Full Code Here

   * @param args the boot application args
   * @param <T> return type
   * @return the value from an execution
   */
  public <T> T execute(SpringApplicationCallback<T> action, String... args) throws SpringApplicationException {
    ConfigurableApplicationContext context = null;
    try {
      context = builder.run(args);
      return action.runWithSpringApplication(context);
    } catch (Exception e) {
      throw new SpringApplicationException("Error executing a spring application", e);
    } finally {
      if (context != null) {
        try {
          context.close();
        }
        catch (Exception e) {
        }
        context = null;
      }
View Full Code Here

@IntegrationTest
public class ApplicationTests {

  @Test
  public void testWebSockets() throws InterruptedException {
    ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("client-context.xml",
        org.springframework.integration.samples.websocket.standard.client.Application.class);
    DirectChannel webSocketInputChannel = ctx.getBean("webSocketInputChannel", DirectChannel.class);

    final CountDownLatch stopLatch = new CountDownLatch(2);

    webSocketInputChannel.addInterceptor(new ChannelInterceptorAdapter() {
      @Override
      public void postSend(Message<?> message, MessageChannel channel, boolean sent) {
        Object payload = message.getPayload();
        assertThat(payload, instanceOf(String.class));
        Date date = null;
        try {
          date = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.DEFAULT).parse((String) payload);
        }
        catch (ParseException e) {
          fail("fail to parse date");
        }
        assertThat(new Date().compareTo(date), greaterThanOrEqualTo(0));
        stopLatch.countDown();
      }

    });
    assertTrue(stopLatch.await(10, TimeUnit.SECONDS));
    ctx.close();
  }
View Full Code Here

@EnableAutoConfiguration
@IntegrationComponentScan
public class Application {

  public static void main(String[] args) throws InterruptedException {
    ConfigurableApplicationContext ctx = SpringApplication.run(Application.class, args);

    Cafe cafe = ctx.getBean(Cafe.class);
    for (int i = 1; i <= 100; i++) {
      Order order = new Order(i);
      order.addItem(DrinkType.LATTE, 2, false);
      order.addItem(DrinkType.MOCHA, 3, true);
      cafe.placeOrder(order);
    }

    Thread.sleep(60000);

    ctx.close();
  }
View Full Code Here

*
*/
public class CNoXML {

  public static void main(String[] args) throws Exception {
    ConfigurableApplicationContext ctx =
        new AnnotationConfigApplicationContext(CConfig.class);
    System.out.println(ctx.getBean(FooService.class).foo("foo"));
    ctx.close();
  }
View Full Code Here

@EnableAutoConfiguration
@IntegrationComponentScan
public class DBoot {

  public static void main(String[] args) throws Exception {
    ConfigurableApplicationContext ctx =
        new SpringApplicationBuilder(DBoot.class)
          .web(false)
          .run(args);
    System.out.println(ctx.getBean(FooService.class).foo("foo"));
    ctx.close();
  }
View Full Code Here

*/
public class FtpOutboundChannelAdapterSample {

  @Test
  public void runDemo() throws Exception{
    ConfigurableApplicationContext ctx =
      new ClassPathXmlApplicationContext("META-INF/spring/integration/DynamicFtpOutboundChannelAdapterSample-context.xml");
    MessageChannel channel = ctx.getBean("toDynRouter", MessageChannel.class);
    File file = File.createTempFile("temp", "txt");
    Message<File> message = MessageBuilder.withPayload(file)
            .setHeader("customer", "cust1")
            .build();
    try {
      channel.send(message);
    }
    catch (MessagingException e) {
      assertThat(e.getCause().getCause().getCause(), instanceOf(UnknownHostException.class));
      assertTrue(e.getCause().getCause().getCause().getMessage().startsWith("host.for.cust1"));
    }
    // send another so we can see in the log we don't create the ac again.
    try {
      channel.send(message);
    }
    catch (MessagingException e) {
      assertThat(e.getCause().getCause().getCause(), instanceOf(UnknownHostException.class));
      assertTrue(e.getCause().getCause().getCause().getMessage().startsWith("host.for.cust1"));
    }
    // send to a different customer; again, check the log to see a new ac is built
    message = MessageBuilder.withPayload(file)
        .setHeader("customer", "cust2").build();
    try {
      channel.send(message);
    }
    catch (MessagingException e) {
      assertThat(e.getCause().getCause().getCause(), instanceOf(UnknownHostException.class));
      assertTrue(e.getCause().getCause().getCause().getMessage().startsWith("host.for.cust2"));
    }

    // send to a different customer; again, check the log to see a new ac is built
    //and the first one created (cust1) should be closed and removed as per the max cache size restriction
    message = MessageBuilder.withPayload(file)
        .setHeader("customer", "cust3").build();
    try {
      channel.send(message);
    }
    catch (MessagingException e) {
      assertThat(e.getCause().getCause().getCause(), instanceOf(UnknownHostException.class));
      assertTrue(e.getCause().getCause().getCause().getMessage().startsWith("host.for.cust3"));
    }

    //send to cust1 again, since this one has been invalidated before, we should
    //see a new ac created (with ac of cust2 destroyed and removed)
    message = MessageBuilder.withPayload(file)
        .setHeader("customer", "cust1").build();
    try {
      channel.send(message);
    }
    catch (MessagingException e) {
      assertThat(e.getCause().getCause().getCause(), instanceOf(UnknownHostException.class));
      assertEquals("host.for.cust1", e.getCause().getCause().getCause().getMessage());
    }

    ctx.close();
  }
View Full Code Here

@IntegrationComponentScan
@EnableAutoConfiguration(exclude = TwitterAutoConfiguration.class)
public class Application {

  public static void main(String[] args) throws Exception {
    ConfigurableApplicationContext ctx = SpringApplication.run(Application.class, args);
    Scanner scanner = new Scanner(System.in);
    String hashTag = scanner.nextLine();
    System.out.println(ctx.getBean(Gateway.class).sendReceive(hashTag));
    scanner.close();
    ctx.close();
  }
View Full Code Here

@ComponentScan
@EnableAutoConfiguration(exclude = TwitterAutoConfiguration.class)
public class Application {

  public static void main(String[] args) throws Exception {
    ConfigurableApplicationContext ctx = SpringApplication.run(Application.class, args);
    System.in.read();
    ctx.close();
  }
View Full Code Here

TOP

Related Classes of org.springframework.context.ConfigurableApplicationContext

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.