本文整理汇总了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();
}
示例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();
}
示例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);
}
示例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();
}
示例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();
}
示例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);
}
示例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================");
}
}
示例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);
}
示例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();
}
示例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());
}
示例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();
}
示例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;
}
示例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);
}
示例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();
}
}
}
}
示例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();
}