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


Java SpringApplicationEvent类代码示例

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


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

示例1: onApplicationEvent

import org.springframework.boot.context.event.SpringApplicationEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(SpringApplicationEvent event) {
	if (this.triggerEventType.isInstance(event)) {
		if (created.compareAndSet(false, true)) {
			try {
				writePidFile(event);
			}
			catch (Exception ex) {
				String message = String.format("Cannot create pid file %s",
						this.file);
				if (failOnWriteError(event)) {
					throw new IllegalStateException(message, ex);
				}
				logger.warn(message, ex);
			}
		}
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:19,代码来源:ApplicationPidFileWriter.java

示例2: writePidFile

import org.springframework.boot.context.event.SpringApplicationEvent; //导入依赖的package包/类
private void writePidFile(SpringApplicationEvent event) throws IOException {
	File pidFile = this.file;
	String override = getProperty(event, FILE_PROPERTIES);
	if (override != null) {
		pidFile = new File(override);
	}
	new ApplicationPid().write(pidFile);
	pidFile.deleteOnExit();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:ApplicationPidFileWriter.java

示例3: getProperty

import org.springframework.boot.context.event.SpringApplicationEvent; //导入依赖的package包/类
private String getProperty(SpringApplicationEvent event, List<Property> candidates) {
	for (Property candidate : candidates) {
		String value = candidate.getValue(event);
		if (value != null) {
			return value;
		}
	}
	return null;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:ApplicationPidFileWriter.java

示例4: getValue

import org.springframework.boot.context.event.SpringApplicationEvent; //导入依赖的package包/类
@Override
public String getValue(SpringApplicationEvent event) {
	Environment environment = getEnvironment(event);
	if (environment == null) {
		return null;
	}
	return new RelaxedPropertyResolver(environment, this.prefix)
			.getProperty(this.key);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:ApplicationPidFileWriter.java

示例5: getEnvironment

import org.springframework.boot.context.event.SpringApplicationEvent; //导入依赖的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

示例6: overridePidFileWithSpring

import org.springframework.boot.context.event.SpringApplicationEvent; //导入依赖的package包/类
@Test
public void overridePidFileWithSpring() throws Exception {
	File file = this.temporaryFolder.newFile();
	SpringApplicationEvent event = createPreparedEvent("spring.pid.file",
			file.getAbsolutePath());
	ApplicationPidFileWriter listener = new ApplicationPidFileWriter();
	listener.onApplicationEvent(event);
	assertThat(FileCopyUtils.copyToString(new FileReader(file))).isNotEmpty();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:ApplicationPidFileWriterTests.java

示例7: differentEventTypes

import org.springframework.boot.context.event.SpringApplicationEvent; //导入依赖的package包/类
@Test
public void differentEventTypes() throws Exception {
	File file = this.temporaryFolder.newFile();
	SpringApplicationEvent event = createEnvironmentPreparedEvent("spring.pid.file",
			file.getAbsolutePath());
	ApplicationPidFileWriter listener = new ApplicationPidFileWriter();
	listener.onApplicationEvent(event);
	assertThat(FileCopyUtils.copyToString(new FileReader(file))).isEmpty();
	listener.setTriggerEventType(ApplicationEnvironmentPreparedEvent.class);
	listener.onApplicationEvent(event);
	assertThat(FileCopyUtils.copyToString(new FileReader(file))).isNotEmpty();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:ApplicationPidFileWriterTests.java

示例8: throwWhenPidFileIsReadOnlyWithSpring

import org.springframework.boot.context.event.SpringApplicationEvent; //导入依赖的package包/类
@Test
public void throwWhenPidFileIsReadOnlyWithSpring() throws Exception {
	File file = this.temporaryFolder.newFile();
	file.setReadOnly();
	SpringApplicationEvent event = createPreparedEvent(
			"spring.pid.fail-on-write-error", "true");
	ApplicationPidFileWriter listener = new ApplicationPidFileWriter(file);
	this.exception.expect(IllegalStateException.class);
	this.exception.expectMessage("Cannot create pid file");
	listener.onApplicationEvent(event);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:ApplicationPidFileWriterTests.java

示例9: createPreparedEvent

import org.springframework.boot.context.event.SpringApplicationEvent; //导入依赖的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

示例10: overridePidFileWithSpring

import org.springframework.boot.context.event.SpringApplicationEvent; //导入依赖的package包/类
@Test
public void overridePidFileWithSpring() throws Exception {
	File file = this.temporaryFolder.newFile();
	SpringApplicationEvent event = createPreparedEvent("spring.pid.file",
			file.getAbsolutePath());
	ApplicationPidFileWriter listener = new ApplicationPidFileWriter();
	listener.onApplicationEvent(event);
	assertThat(FileCopyUtils.copyToString(new FileReader(file)),
			not(isEmptyString()));
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:11,代码来源:ApplicationPidFileWriterTests.java

示例11: differentEventTypes

import org.springframework.boot.context.event.SpringApplicationEvent; //导入依赖的package包/类
@Test
public void differentEventTypes() throws Exception {
	File file = this.temporaryFolder.newFile();
	SpringApplicationEvent event = createEnvironmentPreparedEvent("spring.pid.file",
			file.getAbsolutePath());
	ApplicationPidFileWriter listener = new ApplicationPidFileWriter();
	listener.onApplicationEvent(event);
	assertThat(FileCopyUtils.copyToString(new FileReader(file)), isEmptyString());
	listener.setTriggerEventType(ApplicationEnvironmentPreparedEvent.class);
	listener.onApplicationEvent(event);
	assertThat(FileCopyUtils.copyToString(new FileReader(file)),
			not(isEmptyString()));
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:14,代码来源:ApplicationPidFileWriterTests.java

示例12: failOnWriteError

import org.springframework.boot.context.event.SpringApplicationEvent; //导入依赖的package包/类
private boolean failOnWriteError(SpringApplicationEvent event) {
	String value = getProperty(event, FAIL_ON_WRITE_ERROR_PROPERTIES);
	return (value == null ? false : Boolean.parseBoolean(value));
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:5,代码来源:ApplicationPidFileWriter.java

示例13: createEnvironmentPreparedEvent

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

示例14: setTriggerEventType

import org.springframework.boot.context.event.SpringApplicationEvent; //导入依赖的package包/类
/**
 * Sets the type of application event that will trigger writing of the PID file.
 * Defaults to {@link ApplicationPreparedEvent}. NOTE: If you use the
 * {@link org.springframework.boot.context.event.ApplicationStartedEvent} to trigger
 * the write, you will not be able to specify the PID filename in the Spring
 * {@link Environment}.
 * @param triggerEventType the trigger event type
 */
public void setTriggerEventType(
		Class<? extends SpringApplicationEvent> triggerEventType) {
	Assert.notNull(triggerEventType, "Trigger event type must not be null");
	this.triggerEventType = triggerEventType;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:14,代码来源:ApplicationPidFileWriter.java


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