当前位置: 首页>>代码示例>>Java>>正文


Java ConfigurableApplicationContext.getBean方法代码示例

本文整理汇总了Java中org.springframework.context.ConfigurableApplicationContext.getBean方法的典型用法代码示例。如果您正苦于以下问题:Java ConfigurableApplicationContext.getBean方法的具体用法?Java ConfigurableApplicationContext.getBean怎么用?Java ConfigurableApplicationContext.getBean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.context.ConfigurableApplicationContext的用法示例。


在下文中一共展示了ConfigurableApplicationContext.getBean方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.springframework.context.ConfigurableApplicationContext; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static void main (String[] args){

    ConfigurableApplicationContext ac =
            new ClassPathXmlApplicationContext("/context.xml");
    PollableChannel feedChannel = ac.getBean("feedChannel", PollableChannel.class);

    for (int i = 0; i < 10; i++) {
        Message<SyndEntry> message = (Message<SyndEntry>) feedChannel.receive(1000);
        if (message != null){
            System.out.println("==========="+i+"===========");
            SyndEntry entry = message.getPayload();
            System.out.println(entry.getAuthor());
            System.out.println(entry.getPublishedDate());
            System.out.println(entry.getTitle());
            System.out.println(entry.getUri());
            System.out.println(entry.getLink());
            System.out.println("======================");

        }
    }
    ac.close();


}
 
开发者ID:paulossjunior,项目名称:spring_integration_examples,代码行数:26,代码来源:Application.java

示例2: main

import org.springframework.context.ConfigurableApplicationContext; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
    log.info("Initializing channel node");
    ConfigurableApplicationContext context = SpringApplication.run(ChannelNodeApplication.class, args);
    log.info("Starting API interfaces");
    context.start();
    NodeServer nodeServer = context.getBean(NodeServer.class);
    log.info("Channel node started");
    nodeServer.awaitTermination();
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:10,代码来源:ChannelNodeApplication.java

示例3: when_sending_a_message_containing_tenant_field_should_set_tenant_in_context

import org.springframework.context.ConfigurableApplicationContext; //导入方法依赖的package包/类
@Test
public void when_sending_a_message_containing_tenant_field_should_set_tenant_in_context() {
	String tenantExpected = "client_id";

	ConfigurableApplicationContext context = SpringApplication.run(ApplicationStreamTest.class, "--spring.config.location=classpath:/stream/stream-configuration.properties", "--server.port=0");
	Channel channel = context.getBean(Channel.class);

	//@formatter:off
	Message<?> message = MessageBuilder
							.withPayload("{\"message\":\"any message\",\"tenant\":\"client_id\"}")
							.setHeader("contentType", "application/json")
							.build();
	//@formatter:on

	channel.queue().send(message);
	String tenant = CurrentTenant.get();

	Assert.assertEquals("failure of the tenant recovery process", tenantExpected, tenant);
}
 
开发者ID:wesley-ramos,项目名称:spring-multitenancy,代码行数:20,代码来源:StreamTest.java

示例4: main

import org.springframework.context.ConfigurableApplicationContext; //导入方法依赖的package包/类
public static void main(String[] args) {
	ConfigurableApplicationContext ctx = SpringApplication.run(Application.class, args);
	String welcomeMsg = ctx.getEnvironment().getProperty("app.open.msg");
	ZeroMQEventSubscriber sub = ctx.getBean(ZeroMQEventSubscriber.class);
	System.out.println(welcomeMsg);
	sub.receive();
}
 
开发者ID:edgexfoundry,项目名称:export-distro,代码行数:8,代码来源:Application.java

示例5: main

import org.springframework.context.ConfigurableApplicationContext; //导入方法依赖的package包/类
public static void main(String[] args) {
    // 程序启动入口
    // 启动嵌入式的 Tomcat 并初始化 Spring 环境及其各 Spring 组件
    ConfigurableApplicationContext run = SpringApplication.run(ClientApplication.class, args);
    CityDubboConsumerService cityService = run.getBean(CityDubboConsumerService.class);
    cityService.printCity();
}
 
开发者ID:zcc225,项目名称:springboot-copy,代码行数:8,代码来源:ClientApplication.java

示例6: main

import org.springframework.context.ConfigurableApplicationContext; //导入方法依赖的package包/类
public static void main(String[] args)
        throws InvalidTopologyException, AuthorizationException, AlreadyAliveException, InterruptedException {
    ConfigurableApplicationContext context = SpringApplication.run(DemoApplication.class, args);
    AppMain appMain = context.getBean(AppMain.class);
    appMain.Laugher();
    SpringApplication.exit(context);
}
 
开发者ID:Paleozoic,项目名称:storm_spring_boot_demo,代码行数:8,代码来源:DemoApplication.java

示例7: main

import org.springframework.context.ConfigurableApplicationContext; //导入方法依赖的package包/类
public static void main(String[] args) {
	ConfigurableApplicationContext context = SpringApplication.run(SpringBootRunner.class, args);
	
	Object o = context.getBean("myService");
	System.out.println(o.getClass().getName());
	
	o = context.getBean("myLogik");
	System.out.println(o.getClass().getName());
	
	//	来自其他的包,通过@ComponentScan进行了配置
	//	注入了配置文件
	o = context.getBean("getDemoBean");
	System.out.println(o);
	
	//	测试通过@Import加载的配置是否生效
	o = context.getBean("testImportResource");
	System.out.println(o); 
	
	o = context.getBean("osName");
	
	if(o != null){
		System.out.println("========windows system================");	
	}else{
		System.out.println("========linux   system================");
	}
	
}
 
开发者ID:hutou-workhouse,项目名称:miscroServiceHello,代码行数:28,代码来源:App.java

示例8: EmailUtil

import org.springframework.context.ConfigurableApplicationContext; //导入方法依赖的package包/类
public EmailUtil(ApplicationContext applicationContext)
{
    ApplicationContextFactory subsystem = (ApplicationContextFactory) applicationContext.getBean("OutboundSMTP");
    ConfigurableApplicationContext childContext = (ConfigurableApplicationContext) subsystem.getApplicationContext();

    this.mailActionExecutor = childContext.getBean("mail", ExtendedMailActionExecutor.class);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:8,代码来源:EmailUtil.java

示例9: main

import org.springframework.context.ConfigurableApplicationContext; //导入方法依赖的package包/类
public static void main( String[] args )
    {
        ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("Employee.xml");
        context.getBean("employee");
//        System.out.println( "Hello World!" );
        context.close();
    }
 
开发者ID:garyhu1,项目名称:spring_mvc_demo,代码行数:8,代码来源:App.java

示例10: testSubsystems

import org.springframework.context.ConfigurableApplicationContext; //导入方法依赖的package包/类
/**
 * Test subsystems.
 * 
 * @throws Exception
 *             the exception
 */
public void testSubsystems() throws Exception
{
    ApplicationContextFactory subsystem = (ApplicationContextFactory) getApplicationContext().getBean(
            "testsubsystem");
    ConfigurableApplicationContext childContext = (ConfigurableApplicationContext) subsystem
            .getApplicationContext();
    assertTrue("Subsystem not started", childContext.isActive());
    TestService testService = (TestService) childContext.getBean("testService");
    // Make sure subsystem defaults work
    assertEquals("Subsystem Default1", testService.getSimpleProp1());
    // Make sure global property overrides work
    assertEquals(true, testService.getSimpleProp2().booleanValue());
    // Make sure extension classpath property overrides work
    assertEquals("Instance Override3", testService.getSimpleProp3());
    // Make sure extension classpath Spring overrides work
    assertEquals("An extra bean I changed", childContext.getBean("anotherBean"));
    // Make sure composite properties and their defaults work
    TestBean[] testBeans = testService.getTestBeans();
    assertNotNull("Composite property not set", testBeans);
    assertEquals(3, testBeans.length);
    assertEquals("inst1", testBeans[0].getId());
    assertEquals(false, testBeans[0].isBoolProperty());
    assertEquals(123456789123456789L, testBeans[0].getLongProperty());
    assertEquals("Global Default", testBeans[0].getAnotherStringProperty());
    assertEquals("inst2", testBeans[1].getId());
    assertEquals(true, testBeans[1].isBoolProperty());
    assertEquals(123456789123456789L, testBeans[1].getLongProperty());
    assertEquals("Global Default", testBeans[1].getAnotherStringProperty());
    assertEquals("inst3", testBeans[2].getId());
    assertEquals(false, testBeans[2].isBoolProperty());
    assertEquals(123456789123456789L, testBeans[2].getLongProperty());
    assertEquals("Global Instance Default", testBeans[2].getAnotherStringProperty());
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:40,代码来源:SubsystemsTest.java

示例11: testProxy

import org.springframework.context.ConfigurableApplicationContext; //导入方法依赖的package包/类
public void testProxy() throws Exception {
	// publish service
	bundleContext.registerService(new String[] { DataSource.class.getName(), Comparator.class.getName(),
		InitializingBean.class.getName(), Constants.class.getName() }, new Service(), new Hashtable());

	ConfigurableApplicationContext ctx = getNestedContext();
	assertNotNull(ctx);
	Object proxy = ctx.getBean("service");
	assertNotNull(proxy);
	assertTrue(proxy instanceof DataSource);
	assertTrue(proxy instanceof Comparator);
	assertTrue(proxy instanceof Constants);
	assertTrue(proxy instanceof InitializingBean);
	ctx.close();
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:16,代码来源:NonOSGiLoaderProxyTest.java

示例12: initialize

import org.springframework.context.ConfigurableApplicationContext; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected void initialize() {
	if (!this.initialized.compareAndSet(false, true)) {
		return;
	}
	logger.info("Initializing: " + configurationClass);
	SpringApplicationBuilder builder = new SpringApplicationBuilder(
			configurationClass);
	ConfigurableApplicationContext context = builder.web(false).run();
	context.getAutowireCapableBeanFactory().autowireBean(this);
	String name = context.getEnvironment().getProperty("function.name");
	boolean defaultName = false;
	if (name == null) {
		name = "function";
		defaultName = true;
	}
	if (this.catalog == null) {
		this.function = context.getBean(name, Function.class);
	}
	else {
		this.function = this.catalog.lookupFunction(name);
		this.name = name;
		if (this.function == null) {
			if (defaultName) {
				name = "consumer";
			}
			this.consumer = this.catalog.lookupConsumer(name);
			this.name = name;
			if (this.consumer == null) {
				if (defaultName) {
					name = "supplier";
				}
				this.supplier = this.catalog.lookupSupplier(name);
				this.name = name;
			}
		}
	}
	this.context = context;
}
 
开发者ID:kbastani,项目名称:service-block-samples,代码行数:40,代码来源:SpringFunctionInitializer.java

示例13: testJerseyClient

import org.springframework.context.ConfigurableApplicationContext; //导入方法依赖的package包/类
@Test
public void testJerseyClient() throws Exception {
    File srcDir = new File("../karate-demo/src/test/java");
    File destDir = new File("target/test-classes");
    FileUtils.copyDirectory(srcDir, destDir, f -> true, false);
    ConfigurableApplicationContext context = Application.run(new String[]{"--server.port=0"});
    ServerStartedInitializingBean ss = context.getBean(ServerStartedInitializingBean.class);
    System.setProperty("karate.env", "jersey");
    System.setProperty("demo.server.port", ss.getLocalPort() + "");
    System.setProperty("demo.server.https", "false");
    KarateStats stats = CucumberRunner.parallel(getClass(), 5);
    assertTrue("there are scenario failures", stats.getFailCount() == 0);
}
 
开发者ID:intuit,项目名称:karate,代码行数:14,代码来源:JerseyHttpClientTest.java

示例14: main

import org.springframework.context.ConfigurableApplicationContext; //导入方法依赖的package包/类
public static void main(String[] args) {
    SpringApplicationBuilder builder = new SpringApplicationBuilder(Launcher.class);
    Set<ApplicationListener<?>> listeners = builder.application().getListeners();
    for (Iterator<ApplicationListener<?>> it = listeners.iterator(); it.hasNext();) {
        ApplicationListener<?> listener = it.next();
        if (listener instanceof LoggingApplicationListener) {
            it.remove();
        }
    }
    builder.application().setListeners(listeners);
    ConfigurableApplicationContext context = builder.run(args);
    LOGGER.info("log-generator start successfully");

    GenerateLogService logService = context.getBean(GenerateLogService.class);
    logService.generateCoverLog();



    // 优雅停止项目
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            LOGGER.info("try to stop the system");
            synchronized (Launcher.class) {
                RUNNING = false;
                Launcher.class.notify();
            }
        }
    });

    synchronized (Launcher.class) {
        while (RUNNING) {
            try {
                Launcher.class.wait();
            } catch (InterruptedException e) {
                LOGGER.error("wait error");
                e.printStackTrace();
            }
        }
    }
}
 
开发者ID:JThink,项目名称:SkyEye,代码行数:42,代码来源:Launcher.java

示例15: setUp

import org.springframework.context.ConfigurableApplicationContext; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception
{
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
    {
        fail("Dangling transaction detected, left by a previous test.");
    }
    ctx = (ConfigurableApplicationContext) ApplicationContextHelper.getApplicationContext();
    replicationActionExecutor = (ReplicationActionExecutor) ctx.getBean("replicationActionExecutor");
    replicationService = (ReplicationService) ctx.getBean("replicationService");
    replicationParams = (ReplicationParams) ctx.getBean("replicationParams");
    transactionService = (TransactionService) ctx.getBean("transactionService");
    transferService = (TransferService2) ctx.getBean("transferService2");
    contentService = (ContentService) ctx.getBean("contentService");
    jobLockService = (JobLockService) ctx.getBean("jobLockService");
    actionService = (ActionService) ctx.getBean("actionService");
    scriptService = (ScriptService)ctx.getBean("scriptService");
    nodeService = (NodeService) ctx.getBean("NodeService");
    lockService = (LockService) ctx.getBean("lockService");
    repositoryHelper = (Repository) ctx.getBean("repositoryHelper");
    actionTrackingService = (ActionTrackingService) ctx.getBean("actionTrackingService");
    scheduledPersistedActionService = (ScheduledPersistedActionService) ctx.getBean("scheduledPersistedActionService");
    
    // Set the current security context as admin
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    
    replicationParams.setEnabled(true);
    
    UserTransaction txn = transactionService.getUserTransaction();
    txn.begin();
    
    // Zap any existing replication entries
    replicationRoot = ReplicationDefinitionPersisterImpl.REPLICATION_ACTION_ROOT_NODE_REF;
    for(ChildAssociationRef child : nodeService.getChildAssocs(replicationRoot)) {
       QName type = nodeService.getType( child.getChildRef() );
       if(ReplicationDefinitionPersisterImpl.ACTION_TYPES.contains(type)) {
          nodeService.deleteNode(child.getChildRef());
       }
    }
    
    // Create the test folder structure
    destinationFolder = makeNode(repositoryHelper.getCompanyHome(), ContentModel.TYPE_FOLDER, "ReplicationTransferDestination");
    folder1 = makeNode(repositoryHelper.getCompanyHome(), ContentModel.TYPE_FOLDER);
    folder2 = makeNode(repositoryHelper.getCompanyHome(), ContentModel.TYPE_FOLDER);
    folder2a = makeNode(folder2, ContentModel.TYPE_FOLDER);
    folder2b = makeNode(folder2, ContentModel.TYPE_FOLDER);
    
    content1_1 = makeNode(folder1, ContentModel.TYPE_CONTENT);
    content1_2 = makeNode(folder1, ContentModel.TYPE_CONTENT);
    thumbnail1_3 = makeNode(folder1, ContentModel.TYPE_THUMBNAIL);
    authority1_4 = makeNode(folder1, ContentModel.TYPE_AUTHORITY);
    content2a_1 = makeNode(folder2a, ContentModel.TYPE_CONTENT);
    thumbnail2a_2 = makeNode(folder2a, ContentModel.TYPE_THUMBNAIL);
    zone2a_3 = makeNode(folder2a, ContentModel.TYPE_ZONE);
    
    deletedFolder = makeNode(repositoryHelper.getCompanyHome(), ContentModel.TYPE_FOLDER);
    nodeService.deleteNode(deletedFolder);
    
    // Tell the transfer service not to use HTTP
    makeTransferServiceLocal();
    
    // Finish setup
    txn.commit();
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:65,代码来源:ReplicationServiceIntegrationTest.java


注:本文中的org.springframework.context.ConfigurableApplicationContext.getBean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。