A
A
AndreyPM2012-07-17 21:52:17
Java
AndreyPM, 2012-07-17 21:52:17

MyBatis how to configure the database configuration?

Can you please tell me how to set up a connection to the database in MyBatis-3.1.1 without writing it in config.xml, but using the DataSource?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
ivnik, 2012-07-19
@AndreyPM

I did something like this:

    private SqlSessionFactory createSqlSessionFactory(@Nonnull final DataSource dataSource) {
        final TransactionFactory transactionFactory = new JdbcTransactionFactory();

        final Environment environment = new Environment("main", transactionFactory, dataSource);

        final Configuration configuration = new Configuration(environment);

        // .. добавление mapper-ов
        // configuration.addMapper(mapperClass);

        return new SqlSessionFactoryBuilder().build(configuration);
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question