Need help with configuring custom SQL. Getting error for MapperRegistry

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Active Member

Need help with configuring custom SQL. Getting error for MapperRegistry

Jump to solution

I am trying to configure a custom mybatis query and missing something.  

I created my interface 

package com.activiti.mappers;

import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface CustomMybatisMapper {

@Select("SELECT ID_ FROM ACT_RE_PROCDEF WHERE KEY_ = #{key}")
String loadProcessDefinitionIdByKey(String key);
}

I added an xml file under src/main/resources/mappers/CustomMybatisXmlmapper.xml

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.activiti.mappers.CustomMybatisMapper">

    <!-- SELECT ALL PROCESS DEFINITION ID -->

    <select id="selectProcessDefinitionDeploymentIdByKey" parameterType="String" resultType="String">

        SELECT DEPLOYMENT_ID_ FROM ACT_RE_PROCDEF WHERE KEY_ = #{value}

    </select>

</mapper>

I added an application.properties entry 

spring.activiti.customMybatisXMLMappers[0] = mappers/CustomMybatisXmlMapper.xml

spring.activiti.customMybatisMappers[0] = com.activiti.mappers.CustomMybatisMapper

I put those in the activiti-app.properties too.

The one thing I cannot figure out is this part of the directions.

<property name="customMybatisMappers"> <set> <value>org.activiti.standalone.cfg.MyTestMapper</value> </set> </property>

which in my case would be 

<property name="customMybatisMappers"> <set> <value>com.activiti.mappers.CustomMybatisMapper</value> </set> </property>

Where does this go????   I was also investigating doing the configuration using the 

ProcessEngineConfigurationConfigurer

when I run the following code 

String processDefinitionId = managementService.executeCustomSql(new AbstractCustomSqlExecution<CustomMybatisMapper, String>(CustomMybatisMapper.class) {

            @Override

            public String execute(CustomMybatisMapper customMybatisMapper) {

                return customMybatisMapper.loadProcessDefinitionIdByKey("myprocesskey");

            }

        });

I get:

org.apache.ibatis.binding.BindingException: Type interface com.activiti.mappers.CustomMybatisMapper is not known to the MapperRegistry.

1 Solution

Accepted Solutions
Highlighted
Active Member

Re: Need help with configuring custom SQL. Getting error for MapperRegistry

Jump to solution

Ok after much banging my head agains the desk I have figured it out and will post here to help the next guy.  The documentation I read only gets you so far or assumes you know something which I definitely didn't

I am running in a spring boot configuration in tomcat 

In the pom.xml I added 

<dependency>

<groupId>com.activiti</groupId>

<artifactId>activiti-spring-boot-starter-basic</artifactId>

<version>${activiti.version}</version>

</dependency>

To setup a custom sql query you first create you mapping interface ( i chose com.activiti.mappers as my namespace)

I just used a dummy query for this to see if it worked

package com.activiti.mappers;

import org.apache.ibatis.annotations.Select;

public interface CustomMybatisMapper {

@Select("SELECT ID_ FROM ACT_RE_PROCDEF WHERE KEY_ = #{key}")
String loadProcessDefinitionIdByKey(String key);
}

under com.activiti.extension.conf  namespace I created a configurer and a configuration (the configuration class was the final key for me)

package com.activiti.extension.conf;

import java.util.HashSet;
import java.util.Set;
import org.activiti.spring.SpringProcessEngineConfiguration;
import com.activiti.api.engine.ProcessEngineConfigurationConfigurer;
import org.springframework.context.annotation.Configuration;

import com.activiti.mappers.CustomMybatisMapper;

@Configuration
public class FooCustomMybatisConfigurer implements ProcessEngineConfigurationConfigurer {

@Override
public void processEngineConfigurationInitialized(
SpringProcessEngineConfiguration springProcessEngineConfiguration) {

Set<Class<?>> batisMappers = new HashSet<>();

batisMappers.add(CustomMybatisMapper.class);
springProcessEngineConfiguration.setCustomMybatisMappers(batisMappers);
System.out.println("Mapper added");

}

}

and then the bean creation in the configuration

package com.activiti.extension.conf;

import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;

import com.activiti.api.engine.ProcessEngineConfigurationConfigurer;

@Configuration

public class FooProcessEngineConfig {

@Bean

public ProcessEngineConfigurationConfigurer processEngineConfigurationConfigurer(){

return new FooCustomMybatisConfigurer();

}

}

And the code to call the query

String processDefinitionId = managementService.executeCustomSql(new AbstractCustomSqlExecution<CustomMybatisMapper, String>(CustomMybatisMapper.class) {

            @Override

            public String execute(CustomMybatisMapper customMybatisMapper) {

                return customMybatisMapper.loadProcessDefinitionIdByKey("<your process here>");

            }

        });

No xml configuration needed or properties files tho I am sure you can and maybe should do it that way but this is working.

View solution in original post

1 Reply
Highlighted
Active Member

Re: Need help with configuring custom SQL. Getting error for MapperRegistry

Jump to solution

Ok after much banging my head agains the desk I have figured it out and will post here to help the next guy.  The documentation I read only gets you so far or assumes you know something which I definitely didn't

I am running in a spring boot configuration in tomcat 

In the pom.xml I added 

<dependency>

<groupId>com.activiti</groupId>

<artifactId>activiti-spring-boot-starter-basic</artifactId>

<version>${activiti.version}</version>

</dependency>

To setup a custom sql query you first create you mapping interface ( i chose com.activiti.mappers as my namespace)

I just used a dummy query for this to see if it worked

package com.activiti.mappers;

import org.apache.ibatis.annotations.Select;

public interface CustomMybatisMapper {

@Select("SELECT ID_ FROM ACT_RE_PROCDEF WHERE KEY_ = #{key}")
String loadProcessDefinitionIdByKey(String key);
}

under com.activiti.extension.conf  namespace I created a configurer and a configuration (the configuration class was the final key for me)

package com.activiti.extension.conf;

import java.util.HashSet;
import java.util.Set;
import org.activiti.spring.SpringProcessEngineConfiguration;
import com.activiti.api.engine.ProcessEngineConfigurationConfigurer;
import org.springframework.context.annotation.Configuration;

import com.activiti.mappers.CustomMybatisMapper;

@Configuration
public class FooCustomMybatisConfigurer implements ProcessEngineConfigurationConfigurer {

@Override
public void processEngineConfigurationInitialized(
SpringProcessEngineConfiguration springProcessEngineConfiguration) {

Set<Class<?>> batisMappers = new HashSet<>();

batisMappers.add(CustomMybatisMapper.class);
springProcessEngineConfiguration.setCustomMybatisMappers(batisMappers);
System.out.println("Mapper added");

}

}

and then the bean creation in the configuration

package com.activiti.extension.conf;

import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;

import com.activiti.api.engine.ProcessEngineConfigurationConfigurer;

@Configuration

public class FooProcessEngineConfig {

@Bean

public ProcessEngineConfigurationConfigurer processEngineConfigurationConfigurer(){

return new FooCustomMybatisConfigurer();

}

}

And the code to call the query

String processDefinitionId = managementService.executeCustomSql(new AbstractCustomSqlExecution<CustomMybatisMapper, String>(CustomMybatisMapper.class) {

            @Override

            public String execute(CustomMybatisMapper customMybatisMapper) {

                return customMybatisMapper.loadProcessDefinitionIdByKey("<your process here>");

            }

        });

No xml configuration needed or properties files tho I am sure you can and maybe should do it that way but this is working.

View solution in original post