public static void main(String[] args) {
   GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
   ctx.load("classpath:factorybean/app-context-with-attribute.xml");
   ctx.refresh();
   MessageDigester digester = (MessageDigester) ctx.getBean("digester");
   digester.digest("Hello World!");
 }
  public static void main(String[] args) {

    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:app-context-annotation.xml");
    ctx.refresh();

    ContactDao contactDao = ctx.getBean("contactDao", ContactDao.class);

    // Find and list all contacts
    List<Contact> contacts = contactDao.findAll();
    listContacts(contacts);

    // Find and list all contacts
    /*		contacts = contactDao.findAllWithDetail();
    listContacts(contacts);	*/

    // Find contacts by first name
    contacts = contactDao.findByFirstName("Clarence");
    listContacts(contacts);

    Contact contact;

    // Update contact
    contact = new Contact();
    contact.setId(1l);
    contact.setFirstName("Clarence");
    contact.setLastName("Peter");
    contact.setBirthDate(new Date((new GregorianCalendar(1977, 10, 1)).getTime().getTime()));
    contactDao.update(contact);
    contacts = contactDao.findAll();
    listContacts(contacts);

    // Insert contact
    contact = new Contact();
    contact.setFirstName("Rod");
    contact.setLastName("Johnson");
    contact.setBirthDate(new Date((new GregorianCalendar(2001, 10, 1)).getTime().getTime()));
    contactDao.insert(contact);
    contacts = contactDao.findAll();
    listContacts(contacts);

    // Insert contact with details
    contact = new Contact();
    contact.setFirstName("Michael");
    contact.setLastName("Jackson");
    contact.setBirthDate(new Date((new GregorianCalendar(1964, 10, 1)).getTime().getTime()));
    List<ContactTelDetail> contactTelDetails = new ArrayList<ContactTelDetail>();
    ContactTelDetail contactTelDetail = new ContactTelDetail();
    contactTelDetail.setTelType("Home");
    contactTelDetail.setTelNumber("11111111");
    contactTelDetails.add(contactTelDetail);
    contactTelDetail = new ContactTelDetail();
    contactTelDetail.setTelType("Mobile");
    contactTelDetail.setTelNumber("22222222");
    contactTelDetails.add(contactTelDetail);
    contact.setContactTelDetails(contactTelDetails);
    contactDao.insertWithDetail(contact);
    contacts = contactDao.findAllWithDetail();
    listContacts(contacts);
  }
  public static void main(String[] args) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:applicationContext.xml");
    ctx.refresh();

    while (true) {}
  }
Exemplo n.º 4
0
 public static void main(String[] args) throws Exception {
   GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
   ctx.load("classpath:META-INF/aop-2.xml");
   ctx.refresh();
   MyBean myBean = (MyBean) ctx.getBean("myBean");
   myBean.execute();
 }
  public static void main(String[] args) {
    logger.info("TestClient started");

    // [ Aufgabe 1.6
    GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    context.getEnvironment().setActiveProfiles("mysql");
    context.load("/app/server/bean-definitions.xml");
    context.refresh();
    // ] Aufgabe 1.6  Define application context

    // [ Aufgabe 1.7
    IBookService bean = context.getBean("bookService", IBookService.class);
    // ] Aufgabe 1.7  Receive the bookService from the application context

    BookSearchCriteria criteria = new BookSearchCriteria();
    criteria.setPublicationYear(2007);
    // [ Aufgabe 1.8
    List<Book> books = bean.findBySearchCriteria(criteria);
    // ] Aufgabe 1.8  Read books - List<Book> books = null;

    if (books != null) {
      logger.info("The following books have been found:");
      for (Book book : books) {
        logger.info(book.getAuthor() + ": \"" + book.getTitle() + "\"");
      }
    }
  }
  public static void main(String[] args) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:META-INF/spring/app-context-xml.xml");
    ctx.refresh();

    MyBean myBean = (MyBean) ctx.getBean("myBean");
    myBean.execute();
  }
  public static void main(String[] args) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:META-INF/spring/app-context-annotation.xml");
    ctx.refresh();

    ConstructorConfusion cc = (ConstructorConfusion) ctx.getBean("constructorConfusion");
    System.out.println(cc);
  }
  public static void main(String[] args) {
    GenericXmlApplicationContext parent = new GenericXmlApplicationContext();
    parent.load("classpath:META-INF/spring/parent.xml");
    parent.refresh();

    GenericXmlApplicationContext child = new GenericXmlApplicationContext();
    child.load("classpath:META-INF/spring/app-context-xml.xml");
    child.setParent(parent);
    child.refresh();

    SimpleTarget target1 = (SimpleTarget) child.getBean("target1");
    SimpleTarget target2 = (SimpleTarget) child.getBean("target2");
    SimpleTarget target3 = (SimpleTarget) child.getBean("target3");

    System.out.println(target1.getVal());
    System.out.println(target2.getVal());
    System.out.println(target3.getVal());
  }
  public static void main(String[] args) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:META-INF/spring/app-context-annotation.xml");
    ctx.refresh();

    ContactDao contactDao = ctx.getBean("contactDao", ContactDao.class);

    System.out.println(contactDao.findFirstNameById(1L));
  }
Exemplo n.º 10
0
  public static void main(String[] args) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load(new String[] {"classpath:META-INF/spring/app-context-xml.xml"});
    ctx.refresh();

    MessageWriter writer = new MessageWriter();
    writer.writeMessage();
    writer.foo();
  }
Exemplo n.º 11
0
 public static void main(String[] args) {
   GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
   ctx.load("classpath:/jms-sender-app-context.xml", "classpath:/jms-listener-app-context.xml");
   ctx.refresh();
   MessageSender messageSender = ctx.getBean("messageSender", MessageSender.class);
   for (int i = 0; i < 10; i++) {
     messageSender.sendMessage("Test message: " + i);
   }
 }
  public static void main(String[] args) {

    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:app-context-sf.xml");
    ctx.refresh();

    ContactSfDao contactSfDao = ctx.getBean("contactSfDao", ContactSfDao.class);

    System.out.println(contactSfDao.getFirstNameById(1l));
  }
 public static void main(String[] args) {
   GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
   ctx.load("classpath:app-context.xml");
   ctx.refresh();
   ContactService contactService = ctx.getBean("contactService", ContactService.class);
   List<Contact> contacts;
   // Find all contacts
   contacts = contactService.findAll();
   listContacts(contacts);
 }
  public static void main(String[] args) {

    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    // ctx.load("classpath:app-context-xml.xml");
    ctx.load("classpath:com/shamrov/spring/ioc/annotation/constructor/app-context-annotation.xml");
    ctx.refresh();

    MessageProvider messageProvider = ctx.getBean("messageProvider", MessageProvider.class);

    System.out.println(messageProvider.getMessage());
  }
Exemplo n.º 15
0
  @Test
  public void test01() {
    GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    context.load(TestIocBean.class, new String[] {"app-context-xml.xml"});
    context.refresh();

    MessageProvider messageProvider = context.getBean("messageProvider", MessageProvider.class);
    System.out.println(messageProvider.getMessage());

    MessageRender messageRender = context.getBean("messageRender", MessageRender.class);
    messageRender.render();
  }
Exemplo n.º 16
0
  @Test
  public void test02() {
    GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    // context.load("classpath:app-context-annotation.xml");
    context.load(TestIocBean.class, "app-context-xml.xml");
    context.refresh();

    MessageProvider messageProvider = context.getBean("messageProvider", MessageProvider.class);
    System.out.println(messageProvider.getMessage());

    MessageRender messageRender = context.getBean("messageRender", MessageRender.class);
    messageRender.render();
  }
  @Test
  public void should_read_properties_file_from_profile_a() {

    context.getEnvironment().setDefaultProfiles("default");
    context.getEnvironment().setActiveProfiles("a");
    context.load(
        "classpath:/com/github/jcgay/example/spring/ConfigureBeansWithPropertiesInProfileTest.xml");
    context.refresh();

    BeanWithProperties bean = context.getBean(BeanWithProperties.class);
    BeanWithPropertiesAnnotated annotated = context.getBean(BeanWithPropertiesAnnotated.class);

    assertThat(bean.getTest()).isEqualTo("a");
    assertThat(annotated.getTest()).isEqualTo("a");
  }
Exemplo n.º 18
0
  public static void main(String[] args) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:META-INF/spring/app-context-xml.xml");
    ctx.refresh();

    Target t = null;

    System.out.println("Using byName:\n");
    t = (Target) ctx.getBean("targetByName");

    System.out.println("\nUsing byType:\n");
    t = (Target) ctx.getBean("targetByType");

    System.out.println("\nUsing constructor:\n");
    t = (Target) ctx.getBean("targetConstructor");
  }
Exemplo n.º 19
0
 private DBUtil() {
   ctx = new GenericXmlApplicationContext();
   ctx.load("classpath:META-INF/app-context.xml");
   ctx.refresh();
 }