org.springframework.context.annotation.AnnotationConfigApplicationContext#registerShutdownHook ( )源码实例Demo

下面列出了org.springframework.context.annotation.AnnotationConfigApplicationContext#registerShutdownHook ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

public static void main(String[] args) {
    //XML based Bean Definition Test\
    System.out.println("XML based Bean Definition Inheritance Test");
    ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
    Book book = (Book) context.getBean("BookBean");
    System.out.println("Book Details: " + book);


    //Annotation based Bean Definition Test
    System.out.println("Annotation based Bean Definition Inheritance Test");
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(AppConfig.class);
    ctx.refresh();
    EPubBook ePubBook = ctx.getBean(EPubBook.class);
    System.out.println("Author Name: " + ePubBook.getAuthorName());
    System.out.println("Book Name: " + ePubBook.getBookName());
    System.out.println("Book Price: " + ePubBook.getBookPrice());
    System.out.println("Download URL: " + ePubBook.getDownloadUrl());
    ctx.registerShutdownHook();
}
 
源代码2 项目: Spring-5.0-Cookbook   文件: TestScopes.java
public static void main(String[] args) {
	 AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
	   context.register(BeanConfig.class);
   
	   System.out.println("application context loaded.");
        
       context.refresh();
       System.out.println("*********The empRec1 bean ***************");
       Employee empRec1A = (Employee) context.getBean("empRec1");
       System.out.println("instance A: " + empRec1A.hashCode());
       Employee empRec1B = (Employee) context.getBean("empRec1");
       System.out.println("instance B: " +empRec1B.hashCode());
       
       System.out.println("*********The empRec2 bean ***************");
       Employee empRec2A = (Employee) context.getBean("empRec2");
       System.out.println("instance A: " + empRec2A.hashCode());
       Employee empRec2B = (Employee) context.getBean("empRec2");
       System.out.println("instance B: " + empRec2B.hashCode());
       
       context.registerShutdownHook();
}
 
源代码3 项目: Spring-5.0-Cookbook   文件: TestBeans.java
public static void main(String[] args) {
	   AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
	   context.register(BeanConfig.class);
   
	   System.out.println("application context loaded.");
        
       context.refresh();
       System.out.println("*********The empRec1 bean ***************");
       Employee empRec1 = (Employee) context.getBean("empRec1");
       
       System.out.println("*********The empRec2 bean ***************");
       Employee empRec2 = (Employee) context.getBean("empRec2");
       Department dept2 = empRec2.getDept();
       System.out.println("First Name: " + empRec2.getFirstName());
       System.out.println("Last Name: " + empRec2.getLastName());
       System.out.println("Birthdate: " + empRec2.getBirthdate());
       System.out.println("Salary: " + empRec2.getSalary());
       System.out.println("Dept. Name: " + dept2.getDeptName());
       
       System.out.println("*********The empRec3 bean ***************");
       Employee empRec3 = (Employee) context.getBean("empRec3");
       Department dept3 = empRec3.getDept();
       System.out.println("First Name: " + empRec3.getFirstName());
       System.out.println("Last Name: " + empRec3.getLastName());
       System.out.println("Birthdate: " + empRec3.getBirthdate());
       System.out.println("Salary: " + empRec3.getSalary());
       System.out.println("Dept. Name: " + dept3.getDeptName());
       
       System.out.println("*********The empRec4 bean ***************");
       Employee empRec4 = (Employee) context.getBean("empRec4");
       Department dept4 = empRec4.getDept();
       System.out.println("First Name: " + empRec4.getFirstName());
       System.out.println("Last Name: " + empRec4.getLastName());
       System.out.println("Birthdate: " + empRec4.getBirthdate());
       System.out.println("Salary: " + empRec4.getSalary());
       System.out.println("Dept. Name: " + dept4.getDeptName());
       
       context.registerShutdownHook();
}
 
@Test
void shouldRetrieveNonLeasedSecret() {

	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
			VaultIntegrationTestConfiguration.class, NonRotatingSecret.class);
	context.registerShutdownHook();

	assertThat(context.getEnvironment().getProperty("my-key")).isEqualTo("my-value");

	context.stop();
}
 
@Test
void shouldRetrieveRotatingSecret() {

	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
			VaultIntegrationTestConfiguration.class, RotatingSecret.class);
	context.registerShutdownHook();

	assertThat(context.getEnvironment().getProperty("my-key")).isEqualTo("my-value");

	context.stop();
}
 
源代码6 项目: spring-vertx-ext   文件: SpringVerticleFactory.java
private static void addPostprocessorAndUpdateContext(Class<?> currentVerticleClass,
    AnnotationConfigApplicationContext annotationConfigApplicationContext) {
    annotationConfigApplicationContext.addBeanFactoryPostProcessor(new SpringSingleVerticleConfiguration(currentVerticleClass));
    annotationConfigApplicationContext.refresh();
    annotationConfigApplicationContext.start();
    annotationConfigApplicationContext.registerShutdownHook();
}
 
源代码7 项目: CogStack-Pipeline   文件: Main.java
public static void setUpApplicationContext(ConfigurableEnvironment environment, Properties properties) {
    @SuppressWarnings("resource")
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.registerShutdownHook();
    ctx.setEnvironment(environment);

    // TODO: need a proper way to validate input properties specified by user
    String executionMode = environment.getProperty("execution.mode", "local").toLowerCase();
    if (executionMode != "local" && executionMode != "remote")
        throw new RuntimeException("Invalid execution mode specified. Must be `local` (default) or `remote`.");

    String instanceType = "";
    if (executionMode == "remote")
    {
        if (!environment.containsProperty("execution.instanceType")) {
            throw new RuntimeException("Instance type in remote execution not specified. Must be `master` or `slave`.");
        }

        instanceType = environment.getRequiredProperty("execution.instanceType").toLowerCase();
        if (instanceType != "master" && instanceType != "slave")
            throw new RuntimeException("Invalid instance type in remote execution mode specified. Must be `master` or `slave`.");
    }

    boolean useScheduling;
    try {
        useScheduling = Boolean.parseBoolean(environment.getProperty("scheduler.useScheduling", "false"));
    } catch (Exception e) {
        throw new RuntimeException("Invalid scheduling option specified. Must be `true` or `false` (default).");
    }

    // set appropriate job configuration
    if (executionMode == "remote" && instanceType == "slave") {
        ctx.register(JobConfiguration.class);
        ctx.refresh();
    } else { // execution mode local or remote with master
        if (useScheduling) {
            ctx.register(ScheduledJobLauncher.class);
            ctx.refresh();
        } else {
            ctx.register(SingleJobLauncher.class);
            ctx.refresh();
            SingleJobLauncher launcher = ctx.getBean(SingleJobLauncher.class);
            launcher.launchJob();
        }
    }
}
 
源代码8 项目: minitwit   文件: App.java
public static void main(String[] args) {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(App.class);
	new WebConfig(ctx.getBean(MiniTwitService.class));
    ctx.registerShutdownHook();
}
 
private ConfigurableApplicationContext newApplicationContext(Class<?>... componentClasses) {

		AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();

		applicationContext.register(componentClasses);
		applicationContext.registerShutdownHook();
		applicationContext.refresh();

		this.applicationContext = applicationContext;

		return applicationContext;
	}
 
public static void main(String[] args) {

			AnnotationConfigApplicationContext applicationContext =
				new AnnotationConfigApplicationContext(TestGeodeServerConfiguration.class);

			applicationContext.registerShutdownHook();
		}
 
public static void main(String[] args) {

			AnnotationConfigApplicationContext applicationContext =
				new AnnotationConfigApplicationContext(GeodeServerApplication.class);

			applicationContext.registerShutdownHook();
		}
 
public static void main(String[] args) {

			AnnotationConfigApplicationContext applicationContext =
				new AnnotationConfigApplicationContext(TestGeodeServerConfiguration.class);

			applicationContext.registerShutdownHook();
		}
 
public static void main(String[] args) {

			AnnotationConfigApplicationContext applicationContext =
				new AnnotationConfigApplicationContext(GemFireServerConfiguration.class);

			applicationContext.registerShutdownHook();
		}
 
public static void main(String[] args) {

			AnnotationConfigApplicationContext applicationContext =
				new AnnotationConfigApplicationContext(GemFireServerConfiguration.class);

			applicationContext.registerShutdownHook();
		}
 
public static void main(String[] args) {

			AnnotationConfigApplicationContext applicationContext =
				new AnnotationConfigApplicationContext(GeodeServerTestConfiguration.class);

			applicationContext.registerShutdownHook();
		}