MyBatis Spring: mybatis:scan filter by interface
authorgu.martinm@gmail.com <gu.martinm@gmail.com>
Sun, 9 Feb 2014 13:07:18 +0000 (14:07 +0100)
committergu.martinm@gmail.com <gu.martinm@gmail.com>
Sun, 9 Feb 2014 13:07:18 +0000 (14:07 +0100)
MyBatis/MyBatis-Spring/src/main/java/de/example/mybatis/mapper/filter/MyBatisScanFilter.java [new file with mode: 0644]
MyBatis/MyBatis-Spring/src/main/resources/generator/generatorConfig.xml
MyBatis/MyBatis-Spring/src/main/resources/spring-config.xml

diff --git a/MyBatis/MyBatis-Spring/src/main/java/de/example/mybatis/mapper/filter/MyBatisScanFilter.java b/MyBatis/MyBatis-Spring/src/main/java/de/example/mybatis/mapper/filter/MyBatisScanFilter.java
new file mode 100644 (file)
index 0000000..104a322
--- /dev/null
@@ -0,0 +1,11 @@
+package de.example.mybatis.mapper.filter;
+
+
+/**
+ * 
+ * MyBatis will search for this interface.
+ * 
+ */
+public interface MyBatisScanFilter {
+
+}
index 652403a..3fc63b3 100644 (file)
         <table schema="mybatis_example" tableName="ad" domainObjectName="Ad">
             <property name="useActualColumnNames" value="false" />
             <property name="ignoreQualifiersAtRuntime" value="true" />
+            <!--
+            <mybatis:scan/> supports filtering the mappers created by either specifying a marker interface or an annotation
+            -->
+            <property name="rootInterface" value="de.example.mybatis.mapper.filter.MyBatisScanFilter" />
             <generatedKey column="id" sqlStatement="MySql" identity="false" type="pre" />
         </table>
         <table schema="mybatis_example" tableName="ad_description" domainObjectName="AdDescription">
             <property name="useActualColumnNames" value="false" />
             <property name="ignoreQualifiersAtRuntime" value="true" />
+            <!--
+            <mybatis:scan/> supports filtering the mappers created by either specifying a marker interface or an annotation
+            -->
+            <property name="rootInterface" value="de.example.mybatis.mapper.filter.MyBatisScanFilter" />
             <generatedKey column="id" sqlStatement="MySql" identity="false" type="pre" />
         </table>
     </context>
index 9729c88..0fa5d05 100644 (file)
                            http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring.xsd">
 
 
-    <!-- There is no need to register all your mappers one by one. Instead, you can let MyBatis-Spring scan your classpath for them. -->
-    <mybatis:scan base-package="de.example.mybatis.repository.mapper" />
+    <!--
+    There is no need to register all your mappers one by one. Instead, you can let MyBatis-Spring scan your classpath for them.
+    <mybatis:scan/> supports filtering the mappers created by either specifying a marker interface or an annotation.
+    The annotation property specifies an annotation to search for. The marker-interface attribute specifies a parent interface
+    to search for. If both properties are specified, mappers are added for interfaces that match either criteria. By default,
+    these two properties are null, so all interfaces in the given base package(s) will be loaded as mappers.
+    See http://mybatis.org/schema/mybatis-spring.xsd for further information.
+    -->
+    <mybatis:scan base-package="de.example.mybatis.repository.mapper"
+                  marker-interface="de.example.mybatis.mapper.filter.MyBatisScanFilter" />
 
     <!-- enable the configuration of transactional behavior based on annotations -->
     <tx:annotation-driven transaction-manager="transactionManager"/>