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(String... basePackages) 

Source Link

Document

Create a new AnnotationConfigApplicationContext, scanning for bean definitions in the given packages and automatically refreshing the context.

Usage

From source file:com.khartec.waltz.jobs.UserHarness.java

public static void main(String[] args) {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    UserRoleService userRoleService = ctx.getBean(UserRoleService.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);

    int rc = dsl.insertInto(USER).set(USER.USER_NAME, "kamran").set(USER.PASSWORD, "1234")
            .onDuplicateKeyIgnore().execute();

    System.out.println(rc);/*from   www.ja va  2  s  .c om*/
    //
    //        ImmutableLoginRequest loginRequest = ImmutableLoginRequest.builder()
    //                .userName("dwatkins")
    //                .password("wrong")
    //                .build();
    //
    //        boolean authenticated = userService.authenticate(loginRequest);
    //        System.out.println(authenticated);
    //
    //        userRoleService.findAllUsers().forEach(System.out::println);
}

From source file:com.github.lanimall.ehcache2.AppSpringCacheable.java

public static void main(String[] args) {
    ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);

    MyDataServiceTester tester = (MyDataServiceTester) context.getBean("DataServiceWithSpringCache");
    tester.test();//from   www. ja  v  a  2  s. c o m

    //shut down the Spring context.
    ((ConfigurableApplicationContext) context).close();
}

From source file:com.apress.prospringintegration.springenterprise.stocks.runner.MainJdbcTemplate.java

public static void main(String[] args) {
    GenericApplicationContext context = new AnnotationConfigApplicationContext(
            "com.apress.prospringintegration.springenterprise.stocks.dao.jdbc");

    StockDao stockDao = context.getBean("jdbcTemplateStockDao", StockDao.class);
    Stock stock = new Stock("ORAC", "JDBCTPL0001", "QQQQ", 120.0f, 1100, Calendar.getInstance().getTime());
    stockDao.insert(stock);// www . ja  v  a2s .  co  m

    stock = new Stock("APRS", "JDBCTPL0002", "QQQQ", 150.00F, 1500, Calendar.getInstance().getTime());
    stockDao.insert(stock);

    stock = stockDao.findByInventoryCode("JDBCTPL0001");

    if (stock != null) {
        System.out.println("Template Version");
        System.out.println("Stock Symbol :" + stock.getSymbol());
        System.out.println("Inventory Code :" + stock.getInventoryCode());
        System.out.println("purchased price:" + stock.getSharePrice());
        System.out.println("Exchange ID:" + stock.getExchangeId());
        System.out.println("Quantity Available :" + stock.getQuantityAvailable());
    }
}

From source file:com.grayfox.server.Program.java

public static void main(String[] args) {
    try (AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(
            MainConfig.class)) {
        new Program().run(applicationContext, new Scanner(System.in));
    } catch (Exception ex) {
        LOGGER.error("Error during execution", ex);
    }/*www  .jav a2 s  .  co m*/
}

From source file:dark.robot.analyzer.runner.Application.java

public static void main(String[] args) {
    ApplicationContext context = new AnnotationConfigApplicationContext(Application.class);
}

From source file:com.khartec.waltz.jobs.UserPreferenceHarness.java

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

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);

    UserPreferenceDao userPreferenceDao = ctx.getBean(UserPreferenceDao.class);

    List<UserPreference> preferences = new ArrayList<UserPreference>() {
        {/*  ww w. j av a2 s .c om*/
            add(ImmutableUserPreference.builder().key("org-unit.section.technologies.collapsed").value("false")
                    .build());

            add(ImmutableUserPreference.builder().key("org-unit.section.indicators.collapsed").value("true")
                    .build());

            add(ImmutableUserPreference.builder().key("org-unit.section.logicalflows.collapsed").value("true")
                    .build());

        }
    };

    //        int result = userPreferenceDao.savePreferencesForUser("admin", preferences);
    //        System.out.println("result: " + result);

    int result = userPreferenceDao.savePreference("admin", ImmutableUserPreference.builder()
            .key("org-unit.section.logicalflows.hidden").value("true").build());
    System.out.println("result: " + result);

    //        List<UserPreference> prefs = userPreferenceDao.getPreferencesForUser("admin");
    //        prefs.forEach(u -> System.out.printf("user: %s, key: %s, value: %s\r\n", u.userName(), u.key(), u.value()));

    //        userPreferenceDao.clearPreferencesForUser("kamran");

}

From source file:com.khartec.waltz.jobs.ChangeInitiativeHarness.java

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

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);

    ChangeInitiativeDao dao = ctx.getBean(ChangeInitiativeDao.class);

    ChangeInitiative changeInitiative = dao.getById(1L);
    System.out.println(changeInitiative);

    Collection<ChangeInitiative> changeInitiatives = dao.findForEntityReference(
            ImmutableEntityReference.builder().kind(EntityKind.APP_GROUP).id(2).build());

    System.out.println(changeInitiatives);

}

From source file:jpa.JpaApplication.java

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

    AbstractApplicationContext context = new AnnotationConfigApplicationContext(JpaConfig.class);

    final ThingControl tc = (ThingControl) context.getBean("thingControl");

    Person user = new Person();
    user.setFirstName("Person");
    user.setLastName("Name");

    Thing<Person> pt = tc.createThing("username", user);

    Address address = new Address();
    address.setCity("Auckland");
    address.setCountry("NZ");
    address.setNr(1);/* w  ww .  j  a  va  2s. c o m*/
    address.setStreet("Fleet street");

    Thing<Address> at = tc.createThing("home", address);

    tc.addChildThing(pt, at);

    Object id = pt.getId();
    System.out.println("ID: " + id);

    Role role1 = new Role("role1");
    Thing<Role> r1t = tc.createThing("group_1", role1);

    Role role2 = new Role("role2");
    Thing<Role> r2t = tc.createThing("group_1", role2);

    Role role3 = new Role("role3");
    Thing<Role> r3t = tc.createThing("group_2", role3);

    tc.addChildThing(pt, r1t);
    tc.addChildThing(pt, r2t);
    tc.addChildThing(pt, r3t);

    Observable<? extends Thing<?>> childs = tc.observeChildrenMatchingTypeAndKey(pt, "role", "*2*", true);

    childs.toBlockingObservable().forEach(t -> System.out.println(t));

    Observable<? extends Thing<?>> childs2 = tc.observeChildrenMatchingTypeAndKey(pt, "address", "*", true);

    childs2.toBlockingObservable().forEach(t -> System.out.println(t));

}

From source file:com.khartec.waltz.jobs.AppHarness.java

public static void main(String[] args) {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);

    // Water & Vole
    // P&S Blotter
    // P & S Gorilla

    List<Application> jimmy = new SqlServerAppSearch().search(dsl, "Water & Vole");

    System.out.println(jimmy);/*from  ww  w. j av a2 s .c  o m*/
    //        ApplicationService applicationService = ctx.getBean(ApplicationService.class);
    //        DSLContext dsl = ctx.getBean(DSLContext.class);
    //
    //        List<String> tagList = applicationService.findAllTags();
    //
    //        tagList.forEach(System.out::println);
    //
    //        System.out.println("---------------");
    //
    //        applicationService.findByTag("not-good-at-flying").forEach(a -> System.out.println(a.name()));
    //
    //        System.out.println(applicationService.findTagsForApplication(521L));
    //

}

From source file:ro.fortsoft.pf4j.spring.demo.Boot.java

public static void main(String[] args) {
    // print logo
    printLogo();//from w w  w .  j  a v a  2s  . c o m

    // retrieves the spring application context
    ApplicationContext applicationContext = new AnnotationConfigApplicationContext(Boot.class);

    // print greetings in System.out
    Greetings greetings = applicationContext.getBean(Greetings.class);
    greetings.printGreetings();

    // stop plugins
    PluginManager pluginManager = applicationContext.getBean(PluginManager.class);
    pluginManager.stopPlugins();
}