@Test
  public void testRedisContext() throws Exception {

    System.setProperty("REDIS", "true");

    ClassPathXmlApplicationContext parent =
        new ClassPathXmlApplicationContext("classpath:/server-bootstrap-config.xml");

    try {

      ClassPathXmlApplicationContext context =
          new ClassPathXmlApplicationContext(
              new String[] {"classpath:/servlet-config.xml"}, parent);

      try {

        EnvironmentController controller = context.getBean(EnvironmentController.class);
        assertNotNull(controller);
        Map<String, Properties> env = controller.env();
        assertTrue(env.containsKey("env"));

      } finally {
        context.close();
      }

    } finally {

      System.clearProperty("REDIS");
      parent.close();
    }
  }
Example #2
0
 public static void main(String[] args) {
   System.out.println("Start spring container");
   System.out.println("=======================");
   ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
   System.out.println("Stop spring container");
   System.out.println("=======================");
   context.stop();
   context.close();
   context.destroy();
   System.out.println("Start spring container");
   System.out.println("=======================");
   context = new ClassPathXmlApplicationContext("beans.xml");
   context.close();
   context.destroy();
 }
Example #3
0
 public static void main(String[] args) {
   ClassPathXmlApplicationContext context =
       new ClassPathXmlApplicationContext("ApplicationContext.xml");
   Car c = (Car) context.getBean("carBean");
   System.out.println(c);
   context.close();
 }
Example #4
0
  public void run() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
    EmployeeManager employeeManager = context.getBean(EmployeeManagerImpl.class);
    ProjectManager projectManager = context.getBean(ProjectManagerImpl.class);
    UnitManager unitManager = context.getBean(UnitManagerImpl.class);

    Employee employeeOleksii =
        createEmployee("Junior Java Developer", "Oleksii", EmployeeStatus.NIIGER, 27);
    Employee employeeXZ = createEmployee("Middle Java Developer", "XZ", EmployeeStatus.NIIGER, 27);
    Long employeeOleksiiID = employeeManager.save(employeeOleksii);
    Long employeeXZID = employeeManager.save(employeeXZ);
    logger.info("Employee Oleksii saved with ID: " + employeeOleksiiID);
    logger.info("Employee XZ saved with ID: " + employeeXZID);
    //
    Project project = createProject();
    Long projectID = projectManager.save(project);
    logger.info("Project CTrack saved with ID: " + projectID);

    Unit unit = createUnit();
    Long unitID = unitManager.save(unit);
    logger.info("Unit CTrack saved with ID: " + unitID);

    employeeManager.addToUnit(employeeOleksiiID, unitID);
    employeeManager.addToUnit(employeeXZID, unitID);
    logger.info("Employee with ID: " + employeeOleksiiID + " added to Unit with ID: " + unitID);
    logger.info("Employee with ID: " + employeeXZID + " added to Unit with ID: " + unitID);

    employeeManager.assignToProject(employeeOleksiiID, projectID);
    logger.info(
        "Employee with ID: " + employeeOleksiiID + " assigned to Project with ID: " + projectID);

    // close resources
    context.close();
  }
Example #5
0
 public static void main(String[] args) {
   ApplicationContext context =
       new ClassPathXmlApplicationContext("com/spring/tutorial/di/idref/applicationContext.xml");
   Foo foo = context.getBean("foo", Foo.class);
   LOGGER.info("Foo.bar = " + foo.getBar());
   ((ClassPathXmlApplicationContext) context).close();
 }
 @SuppressWarnings({"unchecked", "rawtypes"})
 public static void main(String[] args) {
   // ch.qos.logback.classic.Logger rootLogger =
   // (ch.qos.logback.classic.Logger)LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
   // rootLogger.setLevel(Level.toLevel("info"));
   final ClassPathXmlApplicationContext ctx =
       new ClassPathXmlApplicationContext(CONFIG, Consumer.class);
   ctx.start();
   final QueueChannel channel = ctx.getBean("inputFromKafka", QueueChannel.class);
   Message msg;
   while ((msg = channel.receive()) != null) {
     HashMap map = (HashMap) msg.getPayload();
     Set<Map.Entry> set = map.entrySet();
     for (Map.Entry entry : set) {
       String topic = (String) entry.getKey();
       System.out.println("Topic:" + topic);
       ConcurrentHashMap<Integer, List<byte[]>> messages =
           (ConcurrentHashMap<Integer, List<byte[]>>) entry.getValue();
       Collection<List<byte[]>> values = messages.values();
       for (Iterator<List<byte[]>> iterator = values.iterator(); iterator.hasNext(); ) {
         List<byte[]> list = iterator.next();
         for (byte[] object : list) {
           String message = new String(object);
           System.out.println("\tMessage : " + message);
         }
       }
     }
   }
   try {
     Thread.sleep(100000);
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
   ctx.close();
 }
  @Test
  public void testServers() throws Exception {
    ClassPathXmlApplicationContext ctx =
        new ClassPathXmlApplicationContext(
            new String[] {"/org/apache/cxf/jaxrs/spring/servers.xml"});

    JAXRSServerFactoryBean sfb = (JAXRSServerFactoryBean) ctx.getBean("simple");
    assertEquals("Get a wrong address", "http://localhost:9090/rs", sfb.getAddress());
    assertNotNull("The resource classes should not be null", sfb.getResourceClasses());
    assertEquals("Get a wrong resource class", BookStore.class, sfb.getResourceClasses().get(0));
    QName serviceQName = new QName("http://books.com", "BookService");
    assertEquals(serviceQName, sfb.getServiceName());
    assertEquals(serviceQName, sfb.getServiceFactory().getServiceName());

    sfb = (JAXRSServerFactoryBean) ctx.getBean("inlineServiceBeans");
    assertNotNull("The resource classes should not be null", sfb.getResourceClasses());
    assertEquals("Get a wrong resource class", BookStore.class, sfb.getResourceClasses().get(0));
    assertEquals(
        "Get a wrong resource class",
        BookStoreSubresourcesOnly.class,
        sfb.getResourceClasses().get(1));

    sfb = (JAXRSServerFactoryBean) ctx.getBean("inlineProvider");
    assertNotNull("The provider should not be null", sfb.getProviders());
    assertEquals("Get a wrong provider size", 2, sfb.getProviders().size());
    verifyJaxbProvider(sfb.getProviders());
    sfb = (JAXRSServerFactoryBean) ctx.getBean("moduleServer");
    assertNotNull("The resource classes should not be null", sfb.getResourceClasses());
    assertEquals("Get a wrong ResourceClasses size", 1, sfb.getResourceClasses().size());
    assertEquals(
        "Get a wrong resource class",
        BookStoreNoAnnotations.class,
        sfb.getResourceClasses().get(0));
    ctx.close();
  }
 public static void main(String[] args) {
   ClassPathXmlApplicationContext context =
       new ClassPathXmlApplicationContext("ApplicationBeans.xml");
   App main = context.getBean(App.class);
   main.run();
   context.close();
 }
Example #9
0
  public static void main(String[] args) {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("beans-cycle.xml");
    Car car = (Car) ctx.getBean("car");
    System.out.println(car);

    // ¹Ø±ÕIOCÈÝÆ÷
    ctx.close();
  }
 public void run() {
   ClassPathXmlApplicationContext context =
       new ClassPathXmlApplicationContext("META-INF/spring/spring.xml");
   subscriberDao = (SubscriberDao) context.getBean("subscriberDaoJpa");
   Subscriber subscriber = save();
   update(subscriber);
   context.close();
 }
 @AfterClass
 public static void generalCleanUp() throws Exception {
   ((JackrabbitRepository) repository).shutdown();
   FileUtils.deleteQuietly(
       new File(PathTestUtil.TARGET_DIR + "tmp" + File.separatorChar + "temp_jackrabbit"));
   context.close();
   SimpleMemoryContextFactory.tearDownAsInitialContext();
 }
 public static void main(String[] args) throws IOException {
   ClassPathXmlApplicationContext context =
       new ClassPathXmlApplicationContext("classpath:appcontext.xml");
   context.start();
   System.out.println("start dubbo server");
   System.in.read(); // 按任意键退出
   context.close();
 }
 @Test
 public void testWebappRootConfiguration() throws Exception {
   ClassPathXmlApplicationContext context =
       new ClassPathXmlApplicationContext(
           "classpath:/org/springframework/batch/admin/web/resources/webapp-config.xml");
   assertTrue(context.containsBean("jobRepository"));
   context.close();
 }
  public static void main(String[] args) throws InterruptedException {

    final ClassPathXmlApplicationContext ctx =
        new ClassPathXmlApplicationContext("src-code-executor-test-ctx.xml");

    Thread.sleep(50000);

    ctx.close();
  }
  public static void main(String[] args) throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/camel.xml");
    CamelContext camelContext = (CamelContext) context.getBean("camelContext");
    camelContext.start();

    Thread.sleep(3000);
    camelContext.stop();
    context.close();
  }
 public static void main(String args[]) throws Exception {
   System.setProperty("serviceUrl", "http://localhost:9090/services/CustomerServicePort");
   ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("/client.xml");
   CustomerServiceTester tester = context.getBean(CustomerServiceTester.class);
   tester.testCustomerService();
   Thread.sleep(2000);
   context.close();
   System.exit(0);
 }
 /**
  * Closes and releases the application context. On the next call to {@link
  * #getApplicationContext(String[])} , a new context will be given.
  */
 public static synchronized void closeApplicationContext() {
   if (instance == null) {
     // Nothing to do
     return;
   }
   instance.close();
   instance = null;
   usedConfiguration = null;
 }
 public static void main(String... args) {
   ClassPathXmlApplicationContext ctx = (ClassPathXmlApplicationContext) getApplicationContext();
   synchronized (ctx) {
     try {
       ctx.wait(10000L);
     } catch (Throwable e) {
     }
   }
   ctx.close();
 }
Example #19
0
 @Test
 public void test1() throws Exception {
   ClassPathXmlApplicationContext context =
       new ClassPathXmlApplicationContext("classpath*:conf/spring/applicationContext*.xml");
   try {
     context.getBean(MyService.class).exec();
   } finally {
     context.close();
   }
 }
Example #20
0
 @Test
 public void shouldInstantiateAllBeans() {
   ClassPathXmlApplicationContext context =
       new ClassPathXmlApplicationContext(getContextFileNames());
   try {
     BeanInstantiater.instantiateBeans(context, true);
   } finally {
     context.close();
   }
 }
 @Test
 public void testBootstrapConfiguration() throws Exception {
   ClassPathXmlApplicationContext context =
       new ClassPathXmlApplicationContext(
           new String[] {
             ClassUtils.addResourcePathToPackagePath(getClass(), "dummy-context.xml"),
             "classpath:/META-INF/spring/batch/bootstrap/**/*.xml"
           });
   assertTrue(context.containsBean("jobRepository"));
   context.close();
 }
Example #22
0
  public static void main(String[] args) {

    ApplicationContext context =
        new ClassPathXmlApplicationContext("com/caveofprogramming/spring/test/beans/beans.xml");
    System.out.println("----");
    Jungle jungle = (Jungle) context.getBean("jungle");

    System.out.println(jungle);
    System.out.println("----");
    ((ClassPathXmlApplicationContext) context).close();
  }
Example #23
0
  public static void main(String[] args) {
    ApplicationContext context =
        new ClassPathXmlApplicationContext(
            "com/coderwurst/spring/robot/annotations/beans/beans.xml");

    Robot robot = (Robot) context.getBean("robot");

    robot.speak();

    ((ClassPathXmlApplicationContext) context).close();
  }
  @Test
  public void testWithAggregatorWithShutdown() {

    ClassPathXmlApplicationContext context1 =
        new ClassPathXmlApplicationContext("gemfire-aggregator-config.xml", this.getClass());
    MessageChannel input = context1.getBean("inputChannel", MessageChannel.class);
    QueueChannel output = context1.getBean("outputChannel", QueueChannel.class);

    Message<?> m1 =
        MessageBuilder.withPayload("1")
            .setSequenceNumber(1)
            .setSequenceSize(3)
            .setCorrelationId(1)
            .build();
    Message<?> m2 =
        MessageBuilder.withPayload("2")
            .setSequenceNumber(2)
            .setSequenceSize(3)
            .setCorrelationId(1)
            .build();
    input.send(m1);
    assertNull(output.receive(1000));
    input.send(m2);
    assertNull(output.receive(1000));

    ClassPathXmlApplicationContext context2 =
        new ClassPathXmlApplicationContext("gemfire-aggregator-config-a.xml", this.getClass());
    MessageChannel inputA = context2.getBean("inputChannel", MessageChannel.class);
    QueueChannel outputA = context2.getBean("outputChannel", QueueChannel.class);

    Message<?> m3 =
        MessageBuilder.withPayload("3")
            .setSequenceNumber(3)
            .setSequenceSize(3)
            .setCorrelationId(1)
            .build();
    inputA.send(m3);
    assertNotNull(outputA.receive(1000));
    context1.close();
    context2.close();
  }
  public static void main(String[] args) {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml");
    EmployeeService employeeService = ctx.getBean("employeeService", EmployeeService.class);

    System.out.println(employeeService.getEmployee().getName());

    //		employeeService.getEmployee().setName("Pankaj");

    //		employeeService.getEmployee().throwException();

    ctx.close();
  }
  public static void main(String[] args) {

    ApplicationContext context =
        new ClassPathXmlApplicationContext("com/fockers/springtest/beans/Beans1.xml");

    Logger logger = (Logger) context.getBean("logger");

    logger.writeFiles("hello there");
    logger.writeConsole("hey");

    ((ClassPathXmlApplicationContext) context).close();
  }
Example #27
0
 @Override
 public void stop() {
   try {
     if (context != null) {
       context.stop();
       context.close();
       context = null;
     }
     log.info(LOGNAME, "{} stopped success.");
   } catch (Throwable e) {
     log.error("{} stopped error:{}", e, LOGNAME);
   }
 }
 @Test
 public void adapterWithTaskExecutor() {
   ClassPathXmlApplicationContext context =
       new ClassPathXmlApplicationContext("jmsInboundWithTaskExecutor.xml", this.getClass());
   JmsMessageDrivenEndpoint endpoint =
       context.getBean("messageDrivenAdapter.adapter", JmsMessageDrivenEndpoint.class);
   DefaultMessageListenerContainer container =
       TestUtils.getPropertyValue(
           endpoint, "listenerContainer", DefaultMessageListenerContainer.class);
   assertSame(context.getBean("exec"), TestUtils.getPropertyValue(container, "taskExecutor"));
   endpoint.stop();
   context.close();
 }
 @Test
 public void adapterWithPubSubDomain() {
   ClassPathXmlApplicationContext context =
       new ClassPathXmlApplicationContext("jmsInboundWithPubSubDomain.xml", this.getClass());
   JmsMessageDrivenEndpoint endpoint =
       context.getBean("messageDrivenAdapter", JmsMessageDrivenEndpoint.class);
   JmsDestinationAccessor container =
       (JmsDestinationAccessor)
           new DirectFieldAccessor(endpoint).getPropertyValue("listenerContainer");
   assertEquals(Boolean.TRUE, container.isPubSubDomain());
   endpoint.stop();
   context.close();
 }
Example #30
0
 public static void main(String[] args) {
   ClassPathXmlApplicationContext classPathXmlApplicationContext = setup();
   Valiant valiant = (Valiant) classPathXmlApplicationContext.getBean("valiant");
   try {
     valiant.execute(args);
   } catch (Exception e) {
     // properly exit the application
     System.err.println("ERROR: " + e.getMessage());
     System.exit(1);
   } finally {
     classPathXmlApplicationContext.close();
   }
 }