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


Java ApplicationPreparedEvent类代码示例

本文整理汇总了Java中org.springframework.boot.context.event.ApplicationPreparedEvent的典型用法代码示例。如果您正苦于以下问题:Java ApplicationPreparedEvent类的具体用法?Java ApplicationPreparedEvent怎么用?Java ApplicationPreparedEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: onApplicationEvent

import org.springframework.boot.context.event.ApplicationPreparedEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationEvent event) {
	if (event instanceof ApplicationStartedEvent) {
		onApplicationStartedEvent((ApplicationStartedEvent) event);
	}
	else if (event instanceof ApplicationEnvironmentPreparedEvent) {
		onApplicationEnvironmentPreparedEvent(
				(ApplicationEnvironmentPreparedEvent) event);
	}
	else if (event instanceof ApplicationPreparedEvent) {
		onApplicationPreparedEvent((ApplicationPreparedEvent) event);
	}
	else if (event instanceof ContextClosedEvent && ((ContextClosedEvent) event)
			.getApplicationContext().getParent() == null) {
		onContextClosedEvent();
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:LoggingApplicationListener.java

示例2: eventsOrder

import org.springframework.boot.context.event.ApplicationPreparedEvent; //导入依赖的package包/类
@Test
public void eventsOrder() {
	SpringApplication application = new SpringApplication(ExampleConfig.class);
	application.setWebEnvironment(false);
	final List<ApplicationEvent> events = new ArrayList<ApplicationEvent>();
	class ApplicationRunningEventListener
			implements ApplicationListener<ApplicationEvent> {
		@Override
		public void onApplicationEvent(ApplicationEvent event) {
			events.add((event));
		}
	}
	application.addListeners(new ApplicationRunningEventListener());
	this.context = application.run();
	assertThat(events).hasSize(5);
	assertThat(events.get(0)).isInstanceOf(ApplicationStartedEvent.class);
	assertThat(events.get(1)).isInstanceOf(ApplicationEnvironmentPreparedEvent.class);
	assertThat(events.get(2)).isInstanceOf(ApplicationPreparedEvent.class);
	assertThat(events.get(3)).isInstanceOf(ContextRefreshedEvent.class);
	assertThat(events.get(4)).isInstanceOf(ApplicationReadyEvent.class);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:22,代码来源:SpringApplicationTests.java

示例3: registerListener

import org.springframework.boot.context.event.ApplicationPreparedEvent; //导入依赖的package包/类
@Test
public void registerListener() throws Exception {
	SpringApplication application = new SpringApplication(ExampleConfig.class,
			ListenerConfig.class);
	application.setApplicationContextClass(SpyApplicationContext.class);
	final LinkedHashSet<ApplicationEvent> events = new LinkedHashSet<ApplicationEvent>();
	application.addListeners(new ApplicationListener<ApplicationEvent>() {

		@Override
		public void onApplicationEvent(ApplicationEvent event) {
			events.add(event);
		}

	});
	this.context = application.run();
	assertThat(events).hasAtLeastOneElementOfType(ApplicationPreparedEvent.class);
	assertThat(events).hasAtLeastOneElementOfType(ContextRefreshedEvent.class);
	verifyTestListenerEvents();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:SpringApplicationTests.java

示例4: registerListenerWithCustomMulticaster

import org.springframework.boot.context.event.ApplicationPreparedEvent; //导入依赖的package包/类
@Test
public void registerListenerWithCustomMulticaster() throws Exception {
	SpringApplication application = new SpringApplication(ExampleConfig.class,
			ListenerConfig.class, Multicaster.class);
	application.setApplicationContextClass(SpyApplicationContext.class);
	final LinkedHashSet<ApplicationEvent> events = new LinkedHashSet<ApplicationEvent>();
	application.addListeners(new ApplicationListener<ApplicationEvent>() {

		@Override
		public void onApplicationEvent(ApplicationEvent event) {
			events.add(event);
		}

	});
	this.context = application.run();
	assertThat(events).hasAtLeastOneElementOfType(ApplicationPreparedEvent.class);
	assertThat(events).hasAtLeastOneElementOfType(ContextRefreshedEvent.class);
	verifyTestListenerEvents();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:SpringApplicationTests.java

示例5: onApplicationEvent

import org.springframework.boot.context.event.ApplicationPreparedEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationEvent event) {
	if (event instanceof ApplicationStartedEvent) {
		onApplicationStartedEvent((ApplicationStartedEvent) event);
	}
	if (event instanceof ApplicationPreparedEvent) {
		Restarter.getInstance()
				.prepare(((ApplicationPreparedEvent) event).getApplicationContext());
	}
	if (event instanceof ApplicationReadyEvent
			|| event instanceof ApplicationFailedEvent) {
		Restarter.getInstance().finish();
		if (event instanceof ApplicationFailedEvent) {
			Restarter.getInstance().prepare(null);
		}
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:RestartApplicationListener.java

示例6: testInitialize

import org.springframework.boot.context.event.ApplicationPreparedEvent; //导入依赖的package包/类
private void testInitialize(boolean failed) {
	Restarter.clearInstance();
	RestartApplicationListener listener = new RestartApplicationListener();
	SpringApplication application = new SpringApplication();
	ConfigurableApplicationContext context = mock(
			ConfigurableApplicationContext.class);
	listener.onApplicationEvent(new ApplicationStartedEvent(application, ARGS));
	assertThat(Restarter.getInstance()).isNotEqualTo(nullValue());
	assertThat(Restarter.getInstance().isFinished()).isFalse();
	listener.onApplicationEvent(
			new ApplicationPreparedEvent(application, ARGS, context));
	if (failed) {
		listener.onApplicationEvent(new ApplicationFailedEvent(application, ARGS,
				context, new RuntimeException()));
	}
	else {
		listener.onApplicationEvent(
				new ApplicationReadyEvent(application, ARGS, context));
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:21,代码来源:RestartApplicationListenerTests.java

示例7: eventsOrder

import org.springframework.boot.context.event.ApplicationPreparedEvent; //导入依赖的package包/类
@Test
public void eventsOrder() {
	SpringApplication application = new SpringApplication(ExampleConfig.class);
	application.setWebEnvironment(false);
	final List<ApplicationEvent> events = new ArrayList<ApplicationEvent>();
	class ApplicationRunningEventListener
			implements ApplicationListener<ApplicationEvent> {
		@Override
		public void onApplicationEvent(ApplicationEvent event) {
			events.add((event));
		}
	}
	application.addListeners(new ApplicationRunningEventListener());
	this.context = application.run();
	assertThat(5, is(events.size()));
	assertThat(events.get(0), is(instanceOf(ApplicationStartedEvent.class)));
	assertThat(events.get(1),
			is(instanceOf(ApplicationEnvironmentPreparedEvent.class)));
	assertThat(events.get(2), is(instanceOf(ApplicationPreparedEvent.class)));
	assertThat(events.get(3), is(instanceOf(ContextRefreshedEvent.class)));
	assertThat(events.get(4), is(instanceOf(ApplicationReadyEvent.class)));
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:23,代码来源:SpringApplicationTests.java

示例8: registerListenerWithCustomMulticaster

import org.springframework.boot.context.event.ApplicationPreparedEvent; //导入依赖的package包/类
@Test
public void registerListenerWithCustomMulticaster() throws Exception {
	SpringApplication application = new SpringApplication(ExampleConfig.class,
			Multicaster.class);
	application.setApplicationContextClass(SpyApplicationContext.class);
	final LinkedHashSet<ApplicationEvent> events = new LinkedHashSet<ApplicationEvent>();
	application.addListeners(new ApplicationListener<ApplicationEvent>() {
		@Override
		public void onApplicationEvent(ApplicationEvent event) {
			events.add(event);
		}
	});
	this.context = application.run();
	assertThat(events, hasItem(isA(ApplicationPreparedEvent.class)));
	assertThat(events, hasItem(isA(ContextRefreshedEvent.class)));
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:17,代码来源:SpringApplicationTests.java

示例9: onApplicationEvent

import org.springframework.boot.context.event.ApplicationPreparedEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationEvent input) {
	if (input instanceof ApplicationPreparedEvent) {
		this.event = (ApplicationPreparedEvent) input;
		if (this.context == null) {
			this.context = this.event.getApplicationContext();
		}
	}
	else if (input instanceof ContextRefreshedEvent) {
		if (this.context != null && input.getSource().equals(this.context)
				&& this.event != null) {
			this.context.publishEvent(this.event);
		}
	}
	else {
		if (this.context != null && input.getSource().equals(this.context)) {
			this.context = null;
			this.event = null;
		}
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:22,代码来源:RestartListener.java

示例10: onApplicationEvent

import org.springframework.boot.context.event.ApplicationPreparedEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationPreparedEvent) {
        if (running == Boolean.FALSE)
            running = Boolean.TRUE;
        if (holdThread == null) {
            holdThread = new Thread(new Runnable() {
                @Override
                public void run() {
                    if (LOGGER.isTraceEnabled()) {
                        LOGGER.trace(Thread.currentThread().getName());
                    }
                    while (running && !Thread.currentThread().isInterrupted()) {
                        try {
                            Thread.sleep(2000);
                        } catch (InterruptedException e) {
                        }
                    }
                }
            }, "Dubbo-Holder");
            holdThread.setDaemon(false);
            holdThread.start();
        }
    }
    if (event instanceof ContextClosedEvent) {
        running = Boolean.FALSE;
        if (null != holdThread) {
            holdThread.interrupt();
            holdThread = null;
        }
    }
}
 
开发者ID:javahongxi,项目名称:whatsmars,代码行数:33,代码来源:DubboHolderListener.java

示例11: onApplicationPreparedEvent

import org.springframework.boot.context.event.ApplicationPreparedEvent; //导入依赖的package包/类
private void onApplicationPreparedEvent(ApplicationPreparedEvent event) {
	ConfigurableListableBeanFactory beanFactory = event.getApplicationContext()
			.getBeanFactory();
	if (!beanFactory.containsBean(LOGGING_SYSTEM_BEAN_NAME)) {
		beanFactory.registerSingleton(LOGGING_SYSTEM_BEAN_NAME, this.loggingSystem);
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:8,代码来源:LoggingApplicationListener.java

示例12: onApplicationEvent

import org.springframework.boot.context.event.ApplicationPreparedEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationEvent event) {
	if (event instanceof ApplicationEnvironmentPreparedEvent) {
		onApplicationEnvironmentPreparedEvent(
				(ApplicationEnvironmentPreparedEvent) event);
	}
	if (event instanceof ApplicationPreparedEvent) {
		onApplicationPreparedEvent(event);
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:11,代码来源:ConfigFileApplicationListener.java

示例13: getEnvironment

import org.springframework.boot.context.event.ApplicationPreparedEvent; //导入依赖的package包/类
private Environment getEnvironment(SpringApplicationEvent event) {
	if (event instanceof ApplicationEnvironmentPreparedEvent) {
		return ((ApplicationEnvironmentPreparedEvent) event).getEnvironment();
	}
	if (event instanceof ApplicationPreparedEvent) {
		return ((ApplicationPreparedEvent) event).getApplicationContext()
				.getEnvironment();
	}
	return null;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:11,代码来源:ApplicationPidFileWriter.java

示例14: createPreparedEvent

import org.springframework.boot.context.event.ApplicationPreparedEvent; //导入依赖的package包/类
private SpringApplicationEvent createPreparedEvent(String propName,
		String propValue) {
	ConfigurableEnvironment environment = createEnvironment(propName, propValue);
	ConfigurableApplicationContext context = mock(
			ConfigurableApplicationContext.class);
	given(context.getEnvironment()).willReturn(environment);
	return new ApplicationPreparedEvent(new SpringApplication(), new String[] {},
			context);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:ApplicationPidFileWriterTests.java

示例15: onApplicationEvent

import org.springframework.boot.context.event.ApplicationPreparedEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationPreparedEvent event) {
    ConfigurableEnvironment environment = event.getApplicationContext().getEnvironment();
    if (StringUtils.hasText(environment.resolvePlaceholders("${dm.config.git.uri:}"))) {
        if (!environment.getPropertySources().contains(this.propertySource.getName())) {
            environment.getPropertySources().addLast(this.propertySource);
        }
    }
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:10,代码来源:ConfigServerBootstrapApplicationListener.java


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