4

I have a my batis (3.2.7) application, and I'm creating configuration using java code ( not xml ) as following.

public static Configuration getConfiguration(DataSet data) {
        if (configuration == null) {
            DataSource dataSource = getDataSource(DRIVER, URL, data.getUsername(), data.getPassword());
            TransactionFactory transactionFactory = new JdbcTransactionFactory();
            Environment environment =
                    new Environment("development", transactionFactory, dataSource);
            configuration = new Configuration(environment);
        }
        return configuration;
}

Using above configuration sql session factory is created.

SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);

My mappers are in xml format ( I need these in xml format), and currently in same package as mapper interface. I'm using following code to add mappers.

configuration.addMapper(CrudMapper.class);

This will automatically add xml mappers which are in same folder as mapper interface ( CrudMapper). But I need to move these xml file to resource folder. So mapper interface will be in one location, and xml mappers are in different location. I could not found any way to add xml mappers to configuration. Is there a way to do this ?

1 Answer 1

6

You are probably adding xml mappers to root of resource folder. Configuration.addMapper should work fine if you preserve package structure in resources folder so that for mapper interface com.company.app.MyMapper corresponding xml mapping is stored in resources/com/company/app/MyMapper.xml.

In this case xml mapping will be put to exactly same package during compilation.

Sign up to request clarification or add additional context in comments.

1 Comment

It worked for me thx, but in my case I need to put my pappers under resourses under mybatis folder, how can we do that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.