Search in sources :

Example 21 with AbstractApplicationContext

use of org.springframework.context.support.AbstractApplicationContext in project dubbo by alibaba.

the class ServiceBean method setApplicationContext.

public void setApplicationContext(ApplicationContext applicationContext) {
    this.applicationContext = applicationContext;
    SpringExtensionFactory.addApplicationContext(applicationContext);
    if (applicationContext != null) {
        SPRING_CONTEXT = applicationContext;
        try {
            // 兼容Spring2.0.1
            Method method = applicationContext.getClass().getMethod("addApplicationListener", new Class<?>[] { ApplicationListener.class });
            method.invoke(applicationContext, new Object[] { this });
            supportedApplicationListener = true;
        } catch (Throwable t) {
            if (applicationContext instanceof AbstractApplicationContext) {
                try {
                    // 兼容Spring2.0.1
                    Method method = AbstractApplicationContext.class.getDeclaredMethod("addListener", new Class<?>[] { ApplicationListener.class });
                    if (!method.isAccessible()) {
                        method.setAccessible(true);
                    }
                    method.invoke(applicationContext, new Object[] { this });
                    supportedApplicationListener = true;
                } catch (Throwable t2) {
                }
            }
        }
    }
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ApplicationListener(org.springframework.context.ApplicationListener) Method(java.lang.reflect.Method)

Example 22 with AbstractApplicationContext

use of org.springframework.context.support.AbstractApplicationContext in project spring-framework by spring-projects.

the class QuartzSchedulerLifecycleTests method destroyLazyInitSchedulerWithCustomShutdownOrderDoesNotHang.

// SPR-6354
@Test
public void destroyLazyInitSchedulerWithCustomShutdownOrderDoesNotHang() {
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("quartzSchedulerLifecycleTests.xml", this.getClass());
    assertNotNull(context.getBean("lazyInitSchedulerWithCustomShutdownOrder"));
    StopWatch sw = new StopWatch();
    sw.start("lazyScheduler");
    context.destroy();
    sw.stop();
    assertTrue("Quartz Scheduler with lazy-init is hanging on destruction: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 500);
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Example 23 with AbstractApplicationContext

use of org.springframework.context.support.AbstractApplicationContext in project opennms by OpenNMS.

the class Main method run.

@Override
public void run() {
    try {
        // Parse arguments to initialize the configuration fields.
        parseArguments(m_args);
        // Test to make sure that we can use ICMP. If not, replace the ICMP
        // implementation with NullPinger.
        initializePinger();
        // If we didn't get authentication information from the command line or
        // system properties, then use an AWT window to prompt the user.
        // Initialize a Spring {@link SecurityContext} that contains the
        // credentials.
        getAuthenticationInfo();
        AbstractApplicationContext context = createAppContext();
        PollerFrontEnd frontEnd = getPollerFrontEnd(context);
        if (!m_gui && !m_scanReport) {
            if (!frontEnd.isRegistered()) {
                if (m_locationName == null) {
                    LOG.error("No location name provided.  You must pass a location name the first time you start the Remote Poller!");
                    System.exit(27);
                } else {
                    frontEnd.register(m_locationName);
                }
            }
        }
    } catch (Throwable e) {
        // a fatal exception occurred
        LOG.error("Exception occurred during registration!", e);
        System.exit(27);
    }
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) PollerFrontEnd(org.opennms.netmgt.poller.remote.PollerFrontEnd)

Example 24 with AbstractApplicationContext

use of org.springframework.context.support.AbstractApplicationContext in project camel by apache.

the class Client method main.

public static void main(String[] args) throws Exception {
    AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext("META-INF/spring/client.xml");
    CamelContext context = applicationContext.getBean("camel", CamelContext.class);
    context.start();
    ProducerTemplate template = context.createProducerTemplate();
    String out = template.requestBodyAndHeader("jms:queue:loan", null, Constants.PROPERTY_SSN, "Client-A", String.class);
    System.out.println(out);
    template.stop();
    context.stop();
}
Also used : CamelContext(org.apache.camel.CamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext)

Example 25 with AbstractApplicationContext

use of org.springframework.context.support.AbstractApplicationContext in project camel by apache.

the class CamelClient method main.

// START SNIPPET: e1
public static void main(final String[] args) throws Exception {
    System.out.println("Notice this client requires that the CamelServer is already running!");
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml");
    // get the camel template for Spring template style sending of messages (= producer)
    ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class);
    System.out.println("Invoking the multiply with 22");
    // as opposed to the CamelClientRemoting example we need to define the service URI in this java code
    int response = (Integer) camelTemplate.sendBody("jms:queue:numbers", ExchangePattern.InOut, 22);
    System.out.println("... the result is: " + response);
    // we're done so let's properly close the application context
    IOHelper.close(context);
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext)

Aggregations

AbstractApplicationContext (org.springframework.context.support.AbstractApplicationContext)27 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)13 Test (org.junit.Test)6 ApplicationContext (org.springframework.context.ApplicationContext)6 CamelContext (org.apache.camel.CamelContext)4 ProducerTemplate (org.apache.camel.ProducerTemplate)3 ComponentLifecycle (com.cloud.utils.component.ComponentLifecycle)2 GlobalSettings (com.openmeap.model.dto.GlobalSettings)2 Method (java.lang.reflect.Method)2 AfterClass (org.junit.AfterClass)2 FileSystemXmlApplicationContext (org.springframework.context.support.FileSystemXmlApplicationContext)2 StopWatch (org.springframework.util.StopWatch)2 AuthorizerImpl (com.openmeap.AuthorizerImpl)1 InvalidPropertiesException (com.openmeap.model.InvalidPropertiesException)1 ModelManager (com.openmeap.model.ModelManager)1 ModelServiceImpl (com.openmeap.model.ModelServiceImpl)1 ClusterNode (com.openmeap.model.dto.ClusterNode)1 MapPayloadEvent (com.openmeap.model.event.MapPayloadEvent)1 Result (com.openmeap.services.dto.Result)1 JSONObject (com.openmeap.thirdparty.org.json.me.JSONObject)1