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());
  }
示例#2
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();
  }
示例#3
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();
  }
 @Override
 public void render() throws RuntimeException {
   if (messageProvider == null) {
     throw new RuntimeException("123");
   }
   System.out.println(messageProvider.getMessage());
 }
 @Override
 public void render() {
   if (messageProvider == null) {
     throw new RuntimeException(
         "You must set the property messageProvider of class:"
             + StandardOutMessageRenderer.class.getName());
   }
   System.out.println(messageProvider.getMessage());
 }
示例#6
0
  protected void initialize(String basename) {

    Messages messagesForBasename = messageProvider.getMessages(basename);
    for (Locale locale : messagesForBasename.getLocales()) {
      Map<String, String> codeToMessage = messagesForBasename.getMessages(locale);
      for (String code : codeToMessage.keySet()) {
        addMessage(basename, locale, code, createMessageFormat(codeToMessage.get(code), locale));
      }
    }
  }
示例#7
0
  public void initialize() {

    resolvingPath = new HashMap<Locale, List<String>>();

    if (!basenameRestriction) {
      basenames = new ArrayList<String>();
      basenames.addAll(messageProvider.getAvailableBaseNames());
    }

    messages = new HashMap<String, Map<String, MessageFormat>>();
    for (String basename : basenames) {
      initialize(basename);
    }
  }
 public void dispatchMessage(Message message) {
   messageDispatcher.dispatch(message);
   messageProvider.free(message);
 }