The data import feature can be easily integrated in the business application.

  • - the importer api interface

  • - abstract class to configure import tasks

  • - data import event listener

  • - base class to create command line task launcher

  • - csv data importer

  • - xml data importer

The ImportTask class can be used to advanced usages like providing input data from arbistrary data streams.

Here is an example:


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.axelor.db.Model;
import com.axelor.test.GuiceModules;
import com.axelor.test.GuiceRunner;

public class CSVTest {

    private Logger log = LoggerFactory.getLogger(getClass());

    private Injector injector;

    public void testCsv() throws ClassNotFoundException {

        final Importer importer = new CSVImporter(
                injector, "/path/to/csv-config.xml"); (1)

        final List<Model> records = new ArrayList<>();
        final Map<String, Object> context = new HashMap<>();

        context.put("CUSTOMER_PHONE", "+3326253225");

        importer.addListener(new Listener() { (2)
            public void imported(Model bean) {
      "Bean saved : {}(id={})",

            public void imported(Integer total, Integer success) {
      "Record (total): " + total);
      "Record (success): " + success);

            public void handle(Model bean, Exception e) {


        importer.runTask(new ImportTask() { (3)

            public void configure() throws IOException {
                // provide input data
                input("customers", new File("customers.csv")); (4)
                input("sales", new File("sales.csv"));

            public boolean handle(ImportException exception) { (5)
                log.error("Import error : " + exception);
                return false;

            public boolean handle(IOException e) { (6)
                log.error("IOException error : " + e);
                return true;
1 create a csv importer (subject to change in v4)
2 add a data import event listener (optional, for statistics)
3 run a data import task with the given task instance
4 provide data input streams
5 handle data import error, continue data import if returns true
6 handle input errors, continue data import if returns true

Same way, you can use XMLImporter class.