I was reading the example that ships with Ibatis and the initializer block
has this comment before configuring the SQL Map. I was just curious what is
the best practice of configuring one if not in the class initializer / a
constructor? I was hoping to call the class as part of the servlet init.

  /**
   * It's not a good idea to put code that can fail in a class initializer,
   * but for sake of argument, here's how you configure an SQL Map.
   */
  static {
    try {
      Reader reader =
Resources.getResourceAsReader("com/mydomain/data/SqlMapConfig.xml");
      sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
      reader.close();
    } catch (IOException e) {
      // Fail fast.
      throw new RuntimeException("Something bad happened while building the
SqlMapClient instance." + e, e);
    }


Thanks,
Anoop

Reply via email to