A few days ago, I started studying MyBatis, a persistence framework for Java. Along its XML configuration settings, there is a <environment> section available for specifying different environment profiles (development, test, production and the like). Basically, it looks like this:

<environments default="development">
    <environment id="development">
        <transactionManager type="JDBC">
        ...
        <dataSource type="POOLED">
        ...
    </environment>
    <environment id="production">
        <transactionManager type="MANAGED">
        ...
        <dataSource type="JNDI">
        ...
    </environment>
</environments>

As I started writing tests for a example webapp I was creating, I quickly felt the need to organize these different environment profiles using a simple mechanism, in order to easily get a SqlSessionFactory instance with the right environment setting whenever I needed. e.g: when testing, I needed an instance using the “test” environment profile.