title: JDBI No Mapper Registered
body: <p>I am evaluating JDBI as a possible alternative to Spring JDBC and MyBatis but encountering some issues. I am using JDBI with Spring Boot 1.2.5 so Spring 4.</p>
  
  <p>I am getting the following stacktrace, shown below. What am I doing wrong? The docs seems kind of lacking. </p>
  
  <pre><code>org.skife.jdbi.v2.MappingRegistry$1: No mapper registered for net.jkratz.ams.domain.User
      at org.skife.jdbi.v2.MappingRegistry.mapperFor(MappingRegistry.java:78)
      at org.skife.jdbi.v2.RegisteredMapper.map(RegisteredMapper.java:37)
      at org.skife.jdbi.v2.Query$4.munge(Query.java:183)
      at org.skife.jdbi.v2.QueryResultSetMunger.munge(QueryResultSetMunger.java:43)
      at org.skife.jdbi.v2.SQLStatement.internalExecute(SQLStatement.java:1340)
      at org.skife.jdbi.v2.Query.fold(Query.java:173)
      at org.skife.jdbi.v2.Query.list(Query.java:82)
      at org.skife.jdbi.v2.Query.list(Query.java:75)
      at net.jkratz.ams.dao.UserDao.getUsers(UserDao.java:28)
      at net.jkratz.ams.dao.UserDao$$FastClassBySpringCGLIB$$5459a2dd.invoke(&lt;generated&gt;)
      at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:717)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
      at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653)
      at net.jkratz.ams.dao.UserDao$$EnhancerBySpringCGLIB$$91d5254a.getUsers(&lt;generated&gt;)
      at net.jkratz.ams.AmsApplicationTests.testJdbi(AmsApplicationTests.java:27)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:73)
      at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
      at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:73)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:224)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:68)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
      at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
      at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
  </code></pre>
  
  <p>Here is my configuration for Spring</p>
  
  <pre><code>@Configuration
  @EnableTransactionManagement
  public class PersistenceConfig {
  
      @Autowired
      Environment environment;
  
      @Bean(name = "datasource")
      public ComboPooledDataSource dataSource() throws PropertyVetoException {
          ComboPooledDataSource dataSource = new ComboPooledDataSource();
          dataSource.setDriverClass(environment.getRequiredProperty("c3p0.driver"));
          dataSource.setJdbcUrl(environment.getRequiredProperty("c3p0.url"));
          dataSource.setUser(environment.getRequiredProperty("c3p0.user"));
          dataSource.setPassword(environment.getRequiredProperty("c3p0.password"));
          dataSource.setInitialPoolSize(environment.getRequiredProperty("c3p0.initialPoolSize", Integer.class));
          dataSource.setMaxPoolSize(environment.getRequiredProperty("c3p0.maxPoolSize", Integer.class));
          dataSource.setMinPoolSize(environment.getRequiredProperty("c3p0.minPoolSize", Integer.class));
          dataSource.setAcquireIncrement(environment.getRequiredProperty("c3p0.acquireIncrement", Integer.class));
          dataSource.setMaxStatements(environment.getRequiredProperty("c3p0.maxStatements", Integer.class));
          dataSource.setMaxIdleTime(environment.getRequiredProperty("c3p0.maxIdleTime", Integer.class));
          return dataSource;
      }
  
      @Bean(name = "dbi")
      public DBIFactoryBean dbiFactoryBean() throws PropertyVetoException {
          DBIFactoryBean dbiFactoryBean = new DBIFactoryBean();
          dbiFactoryBean.setDataSource(dataSource());
          return dbiFactoryBean;
      }
  }
  </code></pre>
  
  <p>Here is my User class</p>
  
  <pre><code>public class User implements Serializable {
  
      private long id;
      private String userName;
      private String password;
      private String passwordHashed;
      private String firstName;
      private String lastName;
      private boolean locked;
      private Date createdAt;
      private Date updatedAt;
  
      ....
  }
  </code></pre>
  
  <p>My DAO</p>
  
  <pre><code>@Repository
  @RegisterMapper(UserMapper.class)
  public class UserDao {
  
      @Autowired
      IDBI dbi;
  
      public UserDao() {
  
      }
  
      public List&lt;User&gt; getUsers() {
          Handle h = dbi.open();
          List&lt;User&gt; users = h.createQuery("select * from users")
              .map(UserMapper.class).mapTo(User.class).list();
          h.close();
          return users;
      }
  }
  </code></pre>
  
  <p>And my Mapper</p>
  
  <pre><code>public class UserMapper implements ResultSetMapper&lt;User&gt; {
  
      @Override
      public User map(int i, ResultSet resultSet, StatementContext statementContext) throws SQLException {
          User user = new User();
          user.setId(resultSet.getLong("id"));
          user.setUserName(resultSet.getString("username"));
          user.setPasswordHashed(resultSet.getString("password"));
          return user;
      }
  }
  </code></pre>