Example usage for org.springframework.context.annotation AnnotationConfigApplicationContext AnnotationConfigApplicationContext

List of usage examples for org.springframework.context.annotation AnnotationConfigApplicationContext AnnotationConfigApplicationContext

Introduction

In this page you can find the example usage for org.springframework.context.annotation AnnotationConfigApplicationContext AnnotationConfigApplicationContext.

Prototype

public AnnotationConfigApplicationContext() 

Source Link

Document

Create a new AnnotationConfigApplicationContext that needs to be populated through #register calls and then manually #refresh refreshed .

Usage

From source file:lab.example.service.MessageListener.java

public static void main(String[] args) throws Exception {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(MessageListener.class);

    SpringApplication application = new SpringApplication(MessageListener.class);

    application.setApplicationContextClass(AnnotationConfigApplicationContext.class);
    SpringApplication.run(MessageListener.class, args);
}

From source file:com.rytis.oot2.AppJavaConfig.java

public static void run(String[] args) throws Throwable {
    SpringApplication.run(AppJavaConfig.class, args);
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
    applicationContext.scan("com.rytis.oot2");
    applicationContext.refresh();/* w  w  w .j  a  v  a  2 s.co m*/

    Device device;
    device = applicationContext.getBean("device1", Device.class);
    device.Boot();
    device = applicationContext.getBean("device2", Device.class);
    device.Boot();
    device = applicationContext.getBean("device3", Device.class);
    device.Boot();
    device = applicationContext.getBean("device4", Device.class);
    device.Boot();
    device = applicationContext.getBean("device5", Device.class);
    device.Boot();
    device = applicationContext.getBean("device7", Device.class);
    device.Boot();
    device = applicationContext.getBean("device8", Device.class);
    device.Boot();

    ((AbstractApplicationContext) applicationContext).close();

}

From source file:com.alliander.osgp.acceptancetests.ScopedGivWenZenForSlim.java

private static InstantiationStrategy autowireStepDefinitionClassesWithSpring() {
    rootContext = new AnnotationConfigApplicationContext();

    // Force local timezone to UTC (like platform)
    DateTimeZone.setDefault(DateTimeZone.UTC);
    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

    // Set loglevel to INFO (instead of DEBUG)
    final Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    root.setLevel(Level.INFO);/*from ww w .  j  av  a 2  s.  c  om*/

    rootContext.register(TestApplicationContext.class);
    try {
        rootContext.refresh();
    } catch (final Exception e) {
        // just for debugging...
        throw e;
    }
    return new SpringInstantiationStrategy(rootContext);
}

From source file:kz.aksay.polygraph.desktop.DesignerWorkFlow.java

@Override
public void start(final Stage primaryStage) {

    context = kz.aksay.polygraph.util.ContextUtils.getApplicationContext();
    context.getBean(UserService.class);
    acaContext = new AnnotationConfigApplicationContext();
    acaContext.setParent(context);//ww w.  j a  v  a  2s .  c om
    acaContext.scan("kz.aksay.polygraph.desktop");
    acaContext.refresh();

    LoginPane loginPane = acaContext.getBean(LoginPane.class);

    Scene scene = new Scene(loginPane, 480, 320);
    scene.getStylesheets().add(DesignerWorkFlow.class.getResource("login.css").toExternalForm());

    loginPane.setOnSignInSuccess(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent t) {
            DirectorPane directorPane = acaContext.getBean(DirectorPane.class);
            Scene scene = new Scene(directorPane, 640, 480);
            primaryStage.setScene(scene);
        }
    });

    primaryStage.setScene(scene);
    primaryStage.setTitle("JavaFX Welcome");
    primaryStage.show();
}

From source file:com.bank.config.code.IntegrationTests.java

@Test
public void transferTenDollars() throws InsufficientFundsException {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.getEnvironment().setDefaultProfiles("dev");
    ctx.register(TransferServiceConfig.class, StandaloneDataConfig.class, JndiDataConfig.class);
    ctx.refresh();//from   ww w.j av a2  s.  co m

    TransferService transferService = ctx.getBean(TransferService.class);
    AccountRepository accountRepository = ctx.getBean(AccountRepository.class);

    assertThat(accountRepository.findById("A123").getBalance(), equalTo(100.00));
    assertThat(accountRepository.findById("C456").getBalance(), equalTo(0.00));

    transferService.transfer(10.00, "A123", "C456");

    assertThat(accountRepository.findById("A123").getBalance(), equalTo(90.00));
    assertThat(accountRepository.findById("C456").getBalance(), equalTo(10.00));
}

From source file:org.pdfsam.configuration.ApplicationContextHolder.java

private ApplicationContextHolder() {
    ctx = new AnnotationConfigApplicationContext();
    ctx.setClassLoader(EnhancedClassloaderProvider.classLoader(ctx.getClassLoader()));
    ctx.register(LoggerConfig.class);
    ctx.register(PdfsamConfig.class);
    ctx.getEnvironment().setActiveProfiles(ctx.getEnvironment().getProperty("pdfsam.edition", "COMMUNITY"));
    ctx.scan("org.pdfsam");
    ctx.registerShutdownHook();/*from   ww  w .jav  a  2  s  .  c o  m*/
    ctx.refresh();
}

From source file:io.pivotal.spring.xd.jdbcgpfdist.support.ControlFileTests.java

@Test
public void testLoadFromFactory() {
    context = new AnnotationConfigApplicationContext();
    context.register(Config1.class);
    context.refresh();// w  ww  .j  a va  2s. c  o m

    ControlFile cf = context.getBean(ControlFile.class);
    assertThat(cf.getGploadOutputTable(), is("test"));
    assertThat(cf.getGploadInputDelimiter(), is(','));
    assertThat(cf.getDatabase(), is("gpadmin"));
    assertThat(cf.getUser(), is("gpadmin"));
    assertThat(cf.getHost(), is("mdw.example.org"));
    assertThat(cf.getPort(), is(5432));
    assertThat(cf.getPassword(), nullValue());

    assertThat(cf.getGploadOutputMode(), is(ControlFile.OutputMode.UPDATE));

    assertThat(cf.getGploadOutputMatchColumns(), notNullValue());
    assertThat(cf.getGploadOutputMatchColumns().size(), is(2));
    assertThat(cf.getGploadOutputMatchColumns().get(0), is("col11"));
    assertThat(cf.getGploadOutputMatchColumns().get(1), is("col12"));

    assertThat(cf.getGploadOutputUpdateColumns(), notNullValue());
    assertThat(cf.getGploadOutputUpdateColumns().size(), is(2));
    assertThat(cf.getGploadOutputUpdateColumns().get(0), is("col21"));
    assertThat(cf.getGploadOutputUpdateColumns().get(1), is("col22"));
    assertThat(cf.getGploadOutputUpdateCondition(), is("condition"));

    assertThat(cf.getGploadSqlBefore().get(0), is("select 1 as before"));
    assertThat(cf.getGploadSqlBefore().get(1), is("select 2 as before"));
    assertThat(cf.getGploadSqlAfter().get(0), is("select 1 as after"));
    assertThat(cf.getGploadSqlAfter().get(1), is("select 2 as after"));
}

From source file:zipkin.autoconfigure.ui.ZipkinUiAutoConfigurationTests.java

@Test
public void indexHtmlFromClasspath() {
    context = new AnnotationConfigApplicationContext();
    context.register(PropertyPlaceholderAutoConfiguration.class, ZipkinUiAutoConfiguration.class);
    context.refresh();/*  w w w  . j a v  a2  s. c  om*/

    assertThat(context.getBean(ZipkinUiAutoConfiguration.class).indexHtml).isNotNull();
}

From source file:org.seasar.doma.boot.autoconfigure.TryLookupEntityListenerProviderTest.java

@Test
public void testManaged() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.register(FooListener.class);
    context.refresh();/*w w w.  jav a 2s.co m*/
    TryLookupEntityListenerProvider provider = new TryLookupEntityListenerProvider();
    provider.setApplicationContext(context);
    FooListener listener = provider.get(FooListener.class, FooListener::new);
    assertThat(listener.managed, is(true));
}

From source file:org.springsource.investigation.ReproTests.java

@SuppressWarnings("unchecked")
@Test//ww  w .  j  av  a2 s  .  c o m
public void repro() {
    ConfigurableApplicationContext parent = new GenericApplicationContext();
    parent.refresh();

    AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext();
    child.setParent(parent);
    child.refresh();

    ConfigurableEnvironment env = child.getBean(ConfigurableEnvironment.class);
    assertThat("UNKNOWN ENV", env,
            anyOf(sameInstance(parent.getEnvironment()), sameInstance(child.getEnvironment())));
    assertThat("EXPECTED CHILD CTX ENV", env, sameInstance(child.getEnvironment()));
}