├── .mvn ├── jvm.config ├── maven.config ├── wrapper │ └── maven-wrapper.properties ├── extensions.xml └── settings.xml ├── .gitattributes ├── src ├── site │ ├── resources │ │ ├── images │ │ │ ├── en.png │ │ │ ├── es.png │ │ │ ├── ja.png │ │ │ ├── ko.png │ │ │ └── zh.png │ │ ├── css │ │ │ └── site.css │ │ ├── es │ │ │ └── css │ │ │ │ └── site.css │ │ ├── ja │ │ │ └── css │ │ │ │ └── site.css │ │ ├── ko │ │ │ └── css │ │ │ │ └── site.css │ │ └── zh_CN │ │ │ └── css │ │ │ └── site.css │ ├── zh_CN │ │ └── markdown │ │ │ ├── boot.md │ │ │ ├── README.md │ │ │ ├── using-api.md │ │ │ └── sample.md │ ├── ko │ │ └── markdown │ │ │ ├── boot.md │ │ │ ├── README.md │ │ │ └── using-api.md │ ├── ja │ │ └── markdown │ │ │ ├── boot.md │ │ │ ├── README.md │ │ │ └── using-api.md │ ├── markdown │ │ ├── boot.md │ │ ├── README.md │ │ └── using-api.md │ └── es │ │ └── markdown │ │ ├── boot.md │ │ ├── README.md │ │ └── using-api.md ├── main │ ├── resources │ │ └── META-INF │ │ │ ├── spring.handlers │ │ │ └── spring.schemas │ └── java │ │ └── org │ │ └── mybatis │ │ ├── spring │ │ ├── annotation │ │ │ ├── package-info.java │ │ │ └── MapperScans.java │ │ ├── support │ │ │ └── package-info.java │ │ ├── package-info.java │ │ ├── config │ │ │ ├── package-info.java │ │ │ └── NamespaceHandler.java │ │ ├── batch │ │ │ ├── package-info.java │ │ │ └── builder │ │ │ │ └── package-info.java │ │ ├── transaction │ │ │ ├── package-info.java │ │ │ └── SpringManagedTransactionFactory.java │ │ └── mapper │ │ │ └── package-info.java │ │ └── logging │ │ └── LoggerFactory.java └── test │ ├── resources │ └── org │ │ └── mybatis │ │ └── spring │ │ ├── config │ │ ├── override.properties │ │ ├── lazy.properties │ │ ├── default-scope.properties │ │ ├── placeholders.properties │ │ ├── name-generator.xml │ │ ├── mapper-factory-bean-class.xml │ │ ├── lazy.xml │ │ ├── base-package.xml │ │ ├── factory-ref.xml │ │ ├── template-ref.xml │ │ ├── annotation.xml │ │ ├── marker-interface.xml │ │ ├── marker-and-annotation.xml │ │ ├── default-scope.xml │ │ ├── process-property-placeholders-false.xml │ │ └── process-property-placeholders-true.xml │ │ ├── annotation │ │ ├── override.properties │ │ ├── scan.properties │ │ └── placeholders.properties │ │ ├── submitted │ │ ├── webapp_placeholder │ │ │ ├── conf.properties │ │ │ └── spring.xml │ │ ├── xa │ │ │ └── database-schema.sql │ │ └── autowire │ │ │ ├── database-schema-bar.sql │ │ │ ├── database-schema-foo.sql │ │ │ ├── FooMapper.xml │ │ │ └── BarMapper.xml │ │ ├── filter │ │ ├── config │ │ │ └── application.properties │ │ └── xml │ │ │ ├── default.properties │ │ │ ├── appContextAspectJFilter.xml │ │ │ ├── appContextCustFilter.xml │ │ │ └── appContextInvalidFilter1.xml │ │ ├── batch │ │ └── db │ │ │ ├── database-schema.sql │ │ │ └── database-test-data.sql │ │ ├── sample │ │ ├── db │ │ │ ├── database-test-data.sql │ │ │ └── database-schema.sql │ │ ├── mapper │ │ │ ├── PersonMapper.xml │ │ │ └── UserMapper.xml │ │ └── config │ │ │ ├── applicationContext-mapper.xml │ │ │ ├── applicationContext-scanner.xml │ │ │ ├── applicationContext-batch.xml │ │ │ ├── applicationContext-namespace.xml │ │ │ └── applicationContext-sqlsession.xml │ │ ├── TestMapper2.xml │ │ ├── TestMapper3.xml │ │ ├── mybatis-config.xml │ │ └── TestMapper.xml │ └── java │ └── org │ └── mybatis │ ├── spring │ ├── scan │ │ ├── package-info.java │ │ ├── ScanEnum.java │ │ ├── ScanInterface.java │ │ ├── ScanAnnotation.java │ │ ├── ScanClass1.java │ │ └── ScanClass2.java │ ├── type │ │ ├── package-info.java │ │ ├── SuperType.java │ │ ├── DummyTypeAlias.java │ │ ├── DummyTypeAlias2.java │ │ ├── DummyTypeHandler.java │ │ └── DummyTypeHandler2.java │ ├── submitted │ │ ├── autowire │ │ │ ├── IBar.java │ │ │ ├── IFoo.java │ │ │ ├── BarMapper.java │ │ │ ├── FooMapper.java │ │ │ └── AutowireTest.java │ │ ├── webapp_placeholder │ │ │ ├── Mapper.java │ │ │ └── WebappPlaceholderTest.java │ │ └── xa │ │ │ ├── UserService.java │ │ │ ├── UserMapper.java │ │ │ ├── User.java │ │ │ └── UserServiceImpl.java │ ├── sample │ │ ├── mapper │ │ │ ├── package-info.java │ │ │ └── UserMapper.java │ │ ├── dao │ │ │ ├── UserDao.java │ │ │ └── UserDaoImpl.java │ │ ├── package-info.java │ │ ├── SampleMapperTest.java │ │ ├── SampleScannerTest.java │ │ ├── SampleNamespaceTest.java │ │ ├── SampleJobJavaConfigTest.java │ │ ├── batch │ │ │ └── UserToPersonItemProcessor.java │ │ ├── SampleBatchTest.java │ │ ├── service │ │ │ ├── BarService.java │ │ │ └── FooService.java │ │ ├── AbstractSampleTest.java │ │ ├── SampleEnableTest.java │ │ ├── domain │ │ │ ├── User.java │ │ │ └── Person.java │ │ ├── SampleJobXmlConfigTest.java │ │ ├── SampleSqlSessionTest.java │ │ └── SampleJavaConfigTest.java │ ├── filter │ │ ├── customfilter │ │ │ ├── ExcludeMaker.java │ │ │ ├── AnnoTypeFilter.java │ │ │ └── CustomTypeFilter.java │ │ └── datasource │ │ │ ├── datasource1 │ │ │ ├── DataSource1Mapper.java │ │ │ └── MapperWithAnnoFilter.java │ │ │ ├── datasource2 │ │ │ ├── DataSource2Mapper.java │ │ │ └── DataSource2Mapper1.java │ │ │ └── commonsource │ │ │ ├── CommonDataSourceMapper.java │ │ │ ├── AssignableMapper.java │ │ │ └── AnnoExcludeMapper.java │ ├── TestMapper.java │ ├── annotation │ │ ├── mapper │ │ │ ├── ds1 │ │ │ │ ├── Ds1Mapper.java │ │ │ │ ├── AppConfigWithDefaultMapperScanAndRepeat.java │ │ │ │ └── AppConfigWithDefaultMapperScans.java │ │ │ └── ds2 │ │ │ │ └── Ds2Mapper.java │ │ ├── MyBean.java │ │ └── factory │ │ │ └── SimpleFactoryBean.java │ ├── mapper │ │ ├── MapperClass.java │ │ ├── MapperImplementation.java │ │ ├── MapperSubinterface.java │ │ ├── MapperInterface.java │ │ ├── AppConfigWithDefaultPackageScan.java │ │ ├── AnnotatedMapperZeroMethods.java │ │ ├── child │ │ │ └── MapperChildInterface.java │ │ ├── AnnotatedMapper.java │ │ ├── ScopedProxyMapper.java │ │ └── AnnotatedMapperOnPropertyCondition.java │ ├── config │ │ ├── MyFactoryBean.java │ │ └── MyBean.java │ ├── asyncsynchronization │ │ └── SqlSessionTemplateAsyncAfterCompletionTest.java │ ├── batch │ │ └── domain │ │ │ └── Employee.java │ └── PooledMockDataSource.java │ └── core │ └── jdk │ └── type │ └── AtomicNumberTypeHandler.java ├── renovate.json ├── .gitignore ├── ISSUE_TEMPLATE.md ├── LICENSE_HEADER ├── format.xml ├── .editorconfig ├── .github └── workflows │ ├── sonatype.yaml │ ├── ci.yaml │ ├── site.yaml │ ├── codeql.yaml │ ├── sonar.yaml │ └── coveralls.yaml ├── scripts └── get_latest_version.sh ├── README.md └── NOTICE /.mvn/jvm.config: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /src/site/resources/images/en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mybatis/spring/HEAD/src/site/resources/images/en.png -------------------------------------------------------------------------------- /src/site/resources/images/es.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mybatis/spring/HEAD/src/site/resources/images/es.png -------------------------------------------------------------------------------- /src/site/resources/images/ja.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mybatis/spring/HEAD/src/site/resources/images/ja.png -------------------------------------------------------------------------------- /src/site/resources/images/ko.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mybatis/spring/HEAD/src/site/resources/images/ko.png -------------------------------------------------------------------------------- /src/site/resources/images/zh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mybatis/spring/HEAD/src/site/resources/images/zh.png -------------------------------------------------------------------------------- /src/main/resources/META-INF/spring.handlers: -------------------------------------------------------------------------------- 1 | http\://mybatis.org/schema/mybatis-spring=org.mybatis.spring.config.NamespaceHandler 2 | -------------------------------------------------------------------------------- /.mvn/maven.config: -------------------------------------------------------------------------------- 1 | -Daether.checksums.algorithms=SHA-512,SHA-256,SHA-1,MD5 2 | -Daether.connector.smartChecksums=false 3 | --no-transfer-progress 4 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "config:recommended" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /src/site/zh_CN/markdown/boot.md: -------------------------------------------------------------------------------- 1 | 2 | # 搭配 Spring Boot 3 | 4 | 请查看 [MyBatis Spring-boot-starter](http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure) 子项目获取更多信息。 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /.settings 3 | /.classpath 4 | /.project 5 | *.epoch 6 | *.log 7 | *.iml 8 | /.idea 9 | .mvn/wrapper/maven-wrapper.jar 10 | release.properties 11 | *.releaseBackup 12 | .github/keys/ 13 | -------------------------------------------------------------------------------- /src/site/ko/markdown/boot.md: -------------------------------------------------------------------------------- 1 | 2 | # 스프링 부트 사용하기 3 | 4 | 자세한 내용은 [MyBatis Spring-boot-starter](http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure) 하위 프로젝트 문서를 참조하십시오. 5 | -------------------------------------------------------------------------------- /src/site/ja/markdown/boot.md: -------------------------------------------------------------------------------- 1 | 2 | # Using Spring Boot 3 | 4 | 詳細は [MyBatis Spring-boot-starter](http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure) のドキュメントを参照してください。 5 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/spring.schemas: -------------------------------------------------------------------------------- 1 | http\://mybatis.org/schema/mybatis-spring-1.2.xsd=org/mybatis/spring/config/mybatis-spring.xsd 2 | http\://mybatis.org/schema/mybatis-spring.xsd=org/mybatis/spring/config/mybatis-spring.xsd 3 | -------------------------------------------------------------------------------- /src/site/markdown/boot.md: -------------------------------------------------------------------------------- 1 | 2 | # Using Spring Boot 3 | 4 | Please see the [MyBatis Spring-boot-starter](http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure) sub project docs for details. 5 | -------------------------------------------------------------------------------- /src/site/es/markdown/boot.md: -------------------------------------------------------------------------------- 1 | 2 | # Using Spring Boot 3 | 4 | Please see the [MyBatis Spring-boot-starter](http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure) sub project docs for details. 5 | -------------------------------------------------------------------------------- /ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 9 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionType=source 2 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.12/apache-maven-3.9.12-bin.zip 3 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.4/maven-wrapper-3.3.4.jar 4 | wrapperVersion=3.3.4 5 | -------------------------------------------------------------------------------- /src/site/zh_CN/markdown/README.md: -------------------------------------------------------------------------------- 1 | # 目录 2 | 3 | 此页面用于在GitHub上呈现索引。 4 | 5 | > **NOTE:** 6 | > 7 | > 由于链接目标是在使用maven-site-plugin转换为html的假设下指定的,因此在GitHub上的呈现中有一个锚点已损坏。 8 | 9 | * [简介](./index.md) 10 | * [入门](./getting-started.md) 11 | * [SqlSessionFactoryBean](./factorybean.md) 12 | * [事务](./transactions.md) 13 | * [使用 SqlSession](./sqlsession.md) 14 | * [注入映射器](./mappers.md) 15 | * [Spring Boot](./boot.md) 16 | * [使用 MyBatis API](./using-api.md) 17 | * [Spring Batch](./batch.md) 18 | * [示例代码](./sample.md) 19 | -------------------------------------------------------------------------------- /src/site/ko/markdown/README.md: -------------------------------------------------------------------------------- 1 | # 목차 2 | 3 | 이 페이지는 GitHub에서 인덱스를 렌더링하기 위한 것입니다. 4 | 5 | > **NOTE:** 6 | > 7 | > 링크 대상은 maven-site-plugin을 사용하여 html로 변환된다는 가정하에 지정되므로 GitHub의 렌더링에서 끊어진 앵커가 있습니다. 8 | 9 | * [소개](./index.md) 10 | * [시작하기](./getting-started.md) 11 | * [SqlSessionFactoryBean](./factorybean.md) 12 | * [트랜잭션](./transactions.md) 13 | * [SqlSession 사용](./sqlsession.md) 14 | * [매퍼 주입](./mappers.md) 15 | * [Spring Boot](./boot.md) 16 | * [MyBatis API 사용](./using-api.md) 17 | * [Spring Batch](./batch.md) 18 | * [샘플 코드](./sample.md) 19 | -------------------------------------------------------------------------------- /src/site/ja/markdown/README.md: -------------------------------------------------------------------------------- 1 | # 目次 2 | 3 | このページはGitHub上でドキュメントの目次を表示するため用意したものです。 4 | 5 | > **NOTE:** 6 | > 7 | > リンクはmaven-site-pluginでHTMLに変換することを前提に指定されているため、GitHubでのレンダリングではリンク切れになっているものがあります。 8 | 9 | * [イントロダクション](./index.md) 10 | * [スタートガイド](./getting-started.md) 11 | * [SqlSessionFactoryBean](./factorybean.md) 12 | * [トランザクション](./transactions.md) 13 | * [SqlSessionの利用](./sqlsession.md) 14 | * [Mapperの注入](./mappers.md) 15 | * [Spring Boot](./boot.md) 16 | * [MyBatis APIの利用](./using-api.md) 17 | * [Spring Batch](./batch.md) 18 | * [サンプルコード](./sample.md) 19 | -------------------------------------------------------------------------------- /LICENSE_HEADER: -------------------------------------------------------------------------------- 1 | Copyright ${license.git.copyrightYears} the original author or authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | https://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /src/site/es/markdown/README.md: -------------------------------------------------------------------------------- 1 | # Tabla de contenido 2 | 3 | Esta página es para representar el índice en GitHub. 4 | 5 | > **NOTE:** 6 | > 7 | > Dado que el destino del enlace se especifica asumiendo que se convierte a html con maven-site-plugin, hay un ancla que se rompe en el renderizado en GitHub. 8 | 9 | * [Introducción](./index.md) 10 | * [Primeros pasos](./getting-started.md) 11 | * [SqlSessionFactoryBean](./factorybean.md) 12 | * [Transactions](./transactions.md) 13 | * [Uso de SqlSession](./sqlsession.md) 14 | * [Inyección de Mappers](./mappers.md) 15 | * [Spring Boot](./boot.md) 16 | * [Uso del API de MyBatis](./using-api.md) 17 | * [Spring Batch](./batch.md) 18 | * [Código de ejemplo](./sample.md) 19 | -------------------------------------------------------------------------------- /src/site/markdown/README.md: -------------------------------------------------------------------------------- 1 | # Table of contents 2 | 3 | This page is for rendering index on GitHub. 4 | 5 | > **NOTE:** 6 | > 7 | > Since the link destination is specified on the assumption that it is converted to html with maven-site-plugin, there is an anchor that is broken in the rendering on GitHub. 8 | 9 | * [Introduction](./index.md) 10 | * [Getting Started](./getting-started.md) 11 | * [SqlSessionFactoryBean](./factorybean.md) 12 | * [Transactions](./transactions.md) 13 | * [Using an SqlSession](./sqlsession.md) 14 | * [Injecting Mappers](./mappers.md) 15 | * [Spring Boot](./boot.md) 16 | * [Using the MyBatis API](./using-api.md) 17 | * [Spring Batch](./batch.md) 18 | * [Sample Code](./sample.md) 19 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/config/override.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2010-2025 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | myBean.name=MyBean!! 18 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/annotation/override.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2010-2025 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | myBean.name=MyBean!! 18 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/annotation/scan.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2010-2025 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | mybatis.lazy-initialization=true 18 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/config/lazy.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2010-2025 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | mybatis.lazy-initialization=true 18 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/scan/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.scan; 17 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/type/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.type; 17 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/config/default-scope.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2010-2025 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | mybatis.default-scope=thread 18 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/config/placeholders.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2010-2024 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | scan-package=org.mybatis.spring.mapper 18 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/annotation/placeholders.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2010-2024 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | scan-package=org.mybatis.spring.annotation.mapper.ds1 18 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/scan/ScanEnum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.scan; 17 | 18 | public enum ScanEnum { 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/type/SuperType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.type; 17 | 18 | public class SuperType { 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/scan/ScanInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.scan; 17 | 18 | public interface ScanInterface { 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/scan/ScanAnnotation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.scan; 17 | 18 | public @interface ScanAnnotation { 19 | } 20 | -------------------------------------------------------------------------------- /format.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/spring/annotation/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * Contains MyBatis annotations 18 | */ 19 | package org.mybatis.spring.annotation; 20 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/submitted/autowire/IBar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.submitted.autowire; 17 | 18 | public interface IBar { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/submitted/autowire/IFoo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.submitted.autowire; 17 | 18 | public interface IFoo { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/sample/mapper/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * Package with DAOs/mappers. 18 | */ 19 | package org.mybatis.spring.sample.mapper; 20 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/spring/support/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * Contains Spring3.X support classes for MyBatis. 18 | */ 19 | package org.mybatis.spring.support; 20 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/filter/customfilter/ExcludeMaker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2023 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.filter.customfilter; 17 | 18 | public interface ExcludeMaker { 19 | } 20 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/submitted/webapp_placeholder/conf.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2010-2024 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | basePkg=org.mybatis.spring.submitted.webapp_placeholder 18 | 19 | mybatis.lazy-initialization=true 20 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/submitted/xa/database-schema.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- Copyright 2010-2024 the original author or authors. 3 | -- 4 | -- Licensed under the Apache License, Version 2.0 (the "License"); 5 | -- you may not use this file except in compliance with the License. 6 | -- You may obtain a copy of the License at 7 | -- 8 | -- https://www.apache.org/licenses/LICENSE-2.0 9 | -- 10 | -- Unless required by applicable law or agreed to in writing, software 11 | -- distributed under the License is distributed on an "AS IS" BASIS, 12 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | -- See the License for the specific language governing permissions and 14 | -- limitations under the License. 15 | -- 16 | 17 | CREATE TABLE USERS ( 18 | id integer not null, 19 | name varchar(80) not null 20 | ); 21 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/spring/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * Contains core classes to build the MyBatis integration with Spring3.X. 18 | */ 19 | package org.mybatis.spring; 20 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/submitted/webapp_placeholder/Mapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.submitted.webapp_placeholder; 17 | 18 | public interface Mapper { 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/spring/config/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * Contains the MyBatis namespace schema and element handlers. 18 | */ 19 | package org.mybatis.spring.config; 20 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2010-2022 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | root = true 18 | 19 | [*.{java, xml, sql}] 20 | charset = utf-8 21 | indent_style = space 22 | indent_size = 2 23 | insert_final_newline = true 24 | trim_trailing_whitespace = true 25 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/spring/batch/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * Contains classes to facilitate the migration in Spring-Batch applications. 18 | */ 19 | package org.mybatis.spring.batch; 20 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/spring/transaction/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * Contains core classes to manage MyBatis transactions in Spring3.X. 18 | */ 19 | package org.mybatis.spring.transaction; 20 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/TestMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring; 17 | 18 | public interface TestMapper { 19 | 20 | int findTest(); 21 | 22 | void insertTest(String test); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/filter/datasource/datasource1/DataSource1Mapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2023 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.filter.datasource.datasource1; 17 | 18 | public interface DataSource1Mapper { 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/filter/datasource/datasource2/DataSource2Mapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2023 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.filter.datasource.datasource2; 17 | 18 | public interface DataSource2Mapper { 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/filter/datasource/datasource2/DataSource2Mapper1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2023 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.filter.datasource.datasource2; 17 | 18 | public interface DataSource2Mapper1 { 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/submitted/autowire/BarMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.submitted.autowire; 17 | 18 | public interface BarMapper extends IBar { 19 | String executeBar(); 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/submitted/autowire/FooMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.submitted.autowire; 17 | 18 | public interface FooMapper extends IFoo { 19 | String executeFoo(); 20 | } 21 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/filter/config/application.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2010-2025 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | exclude-filters.regex=org\.mybatis\.spring\.filter\.datasource\.datasource1\..* 18 | exclude-filters.aspectj=*..CommonDataSourceMapper 19 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/filter/datasource/commonsource/CommonDataSourceMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2023 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.filter.datasource.commonsource; 17 | 18 | public interface CommonDataSourceMapper { 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/spring/mapper/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * Contains classes for automatically building MyBatis mapper proxy classes at application startup. 18 | */ 19 | package org.mybatis.spring.mapper; 20 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/type/DummyTypeAlias.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.type; 17 | 18 | import org.apache.ibatis.type.Alias; 19 | 20 | @Alias("testAlias") 21 | public class DummyTypeAlias { 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/submitted/autowire/database-schema-bar.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- Copyright 2010-2024 the original author or authors. 3 | -- 4 | -- Licensed under the Apache License, Version 2.0 (the "License"); 5 | -- you may not use this file except in compliance with the License. 6 | -- You may obtain a copy of the License at 7 | -- 8 | -- https://www.apache.org/licenses/LICENSE-2.0 9 | -- 10 | -- Unless required by applicable law or agreed to in writing, software 11 | -- distributed under the License is distributed on an "AS IS" BASIS, 12 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | -- See the License for the specific language governing permissions and 14 | -- limitations under the License. 15 | -- 16 | 17 | create table bar ( 18 | id varchar(80) not null, 19 | name varchar(80) not null, 20 | constraint pk_user primary key (id) 21 | ); 22 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/submitted/autowire/database-schema-foo.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- Copyright 2010-2024 the original author or authors. 3 | -- 4 | -- Licensed under the Apache License, Version 2.0 (the "License"); 5 | -- you may not use this file except in compliance with the License. 6 | -- You may obtain a copy of the License at 7 | -- 8 | -- https://www.apache.org/licenses/LICENSE-2.0 9 | -- 10 | -- Unless required by applicable law or agreed to in writing, software 11 | -- distributed under the License is distributed on an "AS IS" BASIS, 12 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | -- See the License for the specific language governing permissions and 14 | -- limitations under the License. 15 | -- 16 | 17 | create table foo ( 18 | id varchar(80) not null, 19 | name varchar(80) not null, 20 | constraint pk_user primary key (id) 21 | ); 22 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/annotation/mapper/ds1/Ds1Mapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.annotation.mapper.ds1; 17 | 18 | public interface Ds1Mapper { 19 | default String test() { 20 | return "ds1"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/sample/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.sample.dao; 17 | 18 | import org.mybatis.spring.sample.domain.User; 19 | 20 | public interface UserDao { 21 | User getUser(String userId); 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/type/DummyTypeAlias2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.type; 17 | 18 | import org.apache.ibatis.type.Alias; 19 | 20 | @Alias("testAlias2") 21 | public class DummyTypeAlias2 extends SuperType { 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/batch/db/database-schema.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- Copyright 2010-2024 the original author or authors. 3 | -- 4 | -- Licensed under the Apache License, Version 2.0 (the "License"); 5 | -- you may not use this file except in compliance with the License. 6 | -- You may obtain a copy of the License at 7 | -- 8 | -- https://www.apache.org/licenses/LICENSE-2.0 9 | -- 10 | -- Unless required by applicable law or agreed to in writing, software 11 | -- distributed under the License is distributed on an "AS IS" BASIS, 12 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | -- See the License for the specific language governing permissions and 14 | -- limitations under the License. 15 | -- 16 | 17 | create table employees ( 18 | id integer not null, 19 | name varchar(80) not null, 20 | salary integer not null, 21 | skill varchar(80) not null 22 | ); 23 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/filter/xml/default.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2010-2025 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | filter.custom=org.mybatis.spring.filter.customfilter.CustomTypeFilter 18 | filter.aspectj=*..CommonDataSourceMapper 19 | filter.regex=org\.mybatis\.spring\.filter\.datasource\.datasource1\..* 20 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/mapper/MapperClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.mapper; 17 | 18 | // child class for MapperScannerPostProcessor tests 19 | // ensures classes are not loaded as MapperFactoryBeans 20 | public class MapperClass { 21 | } 22 | -------------------------------------------------------------------------------- /.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | fr.jcgay.maven 22 | maven-profiler 23 | 3.3 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/filter/datasource/commonsource/AssignableMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2023 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.filter.datasource.commonsource; 17 | 18 | import org.mybatis.spring.filter.customfilter.ExcludeMaker; 19 | 20 | public interface AssignableMapper extends ExcludeMaker { 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/filter/datasource/commonsource/AnnoExcludeMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2023 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.filter.datasource.commonsource; 17 | 18 | import org.mybatis.spring.filter.customfilter.AnnoTypeFilter; 19 | 20 | @AnnoTypeFilter 21 | public interface AnnoExcludeMapper { 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/filter/datasource/datasource1/MapperWithAnnoFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2023 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.filter.datasource.datasource1; 17 | 18 | import org.mybatis.spring.filter.customfilter.AnnoTypeFilter; 19 | 20 | @AnnoTypeFilter 21 | public interface MapperWithAnnoFilter { 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/submitted/xa/UserService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.submitted.xa; 17 | 18 | public interface UserService { 19 | 20 | void saveWithNoFailure(User user); 21 | 22 | void saveWithFailure(User user); 23 | 24 | boolean checkUserExists(int id); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/annotation/mapper/ds2/Ds2Mapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.annotation.mapper.ds2; 17 | 18 | import org.springframework.context.annotation.Scope; 19 | 20 | @Scope 21 | public interface Ds2Mapper { 22 | default String test() { 23 | return "ds2"; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/mapper/MapperImplementation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.mapper; 17 | 18 | // implementation of MapperInterface to test conflicting types 19 | final class MapperImplementation implements MapperInterface { 20 | @Override 21 | public void method() { 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/mapper/MapperSubinterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.mapper; 17 | 18 | // interface for MapperScannerPostProcessor tests 19 | // ensures marker interface usage 20 | // has no methods except parent methods 21 | public interface MapperSubinterface extends MapperInterface { 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/mapper/MapperInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.mapper; 17 | 18 | // marker interface for MapperScannerPostProcessor tests 19 | // when used as a marker interface, 20 | // this class should be ignored even though it has methods 21 | public interface MapperInterface { 22 | void method(); 23 | } 24 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/sample/db/database-test-data.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- Copyright 2010-2024 the original author or authors. 3 | -- 4 | -- Licensed under the Apache License, Version 2.0 (the "License"); 5 | -- you may not use this file except in compliance with the License. 6 | -- You may obtain a copy of the License at 7 | -- 8 | -- https://www.apache.org/licenses/LICENSE-2.0 9 | -- 10 | -- Unless required by applicable law or agreed to in writing, software 11 | -- distributed under the License is distributed on an "AS IS" BASIS, 12 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | -- See the License for the specific language governing permissions and 14 | -- limitations under the License. 15 | -- 16 | 17 | insert into users VALUES ( 'u1', 'Pocoyo' ); 18 | insert into users VALUES ( 'u2', 'Pato' ); 19 | insert into users VALUES ( 'u3', 'Eli' ); 20 | insert into users VALUES ( 'u4', 'Valentina' ); 21 | insert into users VALUES ( 'u5', 'Taro Yamada' ); 22 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/spring/batch/builder/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2025 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * Contains classes to builder classes for {@link org.springframework.batch.infrastructure.item.ItemReader} and 18 | * {@link org.springframework.batch.infrastructure.item.ItemWriter}. 19 | * 20 | * @since 2.0.0 21 | */ 22 | package org.mybatis.spring.batch.builder; 23 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/mapper/AppConfigWithDefaultPackageScan.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.mapper; 17 | 18 | import org.mybatis.spring.annotation.MapperScan; 19 | import org.springframework.context.annotation.Configuration; 20 | 21 | @Configuration 22 | @MapperScan 23 | public class AppConfigWithDefaultPackageScan { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/mapper/AnnotatedMapperZeroMethods.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.mapper; 17 | 18 | import org.springframework.stereotype.Component; 19 | 20 | // annotated interface for MapperScannerPostProcessor tests 21 | // ensures annotated class with no methods is not loaded 22 | @Component 23 | public interface AnnotatedMapperZeroMethods { 24 | } 25 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/TestMapper2.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 22 | 23 | 24 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/TestMapper3.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 22 | 23 | 24 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/submitted/autowire/FooMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 24 | 25 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/config/MyFactoryBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.config; 17 | 18 | import org.springframework.beans.factory.FactoryBean; 19 | 20 | public class MyFactoryBean implements FactoryBean { 21 | @Override 22 | public MyBean getObject() { 23 | return new MyBean("factory"); 24 | } 25 | 26 | @Override 27 | public Class getObjectType() { 28 | return MyBean.class; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/mapper/child/MapperChildInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.mapper.child; 17 | 18 | import org.mybatis.spring.mapper.MapperInterface; 19 | import org.springframework.stereotype.Component; 20 | 21 | // interface for MapperScannerPostProcessor tests 22 | // tests subpackage search 23 | @Component 24 | public interface MapperChildInterface extends MapperInterface { 25 | void childMethod(); 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/sample/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.sample.mapper; 17 | 18 | import org.mybatis.spring.sample.domain.User; 19 | 20 | /** 21 | * A org.mybatis.spring sample mapper. This interface will be used by MapperFactoryBean to create a proxy implementation 22 | * at Spring application startup. 23 | */ 24 | public interface UserMapper { 25 | 26 | User getUser(String userId); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/annotation/mapper/ds1/AppConfigWithDefaultMapperScanAndRepeat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.annotation.mapper.ds1; 17 | 18 | import org.mybatis.spring.annotation.MapperScan; 19 | import org.springframework.context.annotation.Configuration; 20 | 21 | @Configuration 22 | @MapperScan 23 | @MapperScan("org.mybatis.spring.annotation.mapper.ds2") 24 | public class AppConfigWithDefaultMapperScanAndRepeat { 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/submitted/xa/UserMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.submitted.xa; 17 | 18 | import org.apache.ibatis.annotations.Insert; 19 | import org.apache.ibatis.annotations.Select; 20 | 21 | public interface UserMapper { 22 | 23 | @Insert("INSERT INTO USERS VALUES(#{id}, #{name})") 24 | void save(User user); 25 | 26 | @Select("SELECT * FROM USERS WHERE ID=#{id}") 27 | User select(int id); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/sample/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * Sample for four usage scenarios. 18 | * 24 | */ 25 | package org.mybatis.spring.sample; 26 | -------------------------------------------------------------------------------- /.github/workflows/sonatype.yaml: -------------------------------------------------------------------------------- 1 | name: Sonatype 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | permissions: read-all 9 | 10 | concurrency: 11 | group: ${{ github.workflow }}-${{ github.ref }} 12 | cancel-in-progress: true 13 | 14 | jobs: 15 | build: 16 | if: github.repository_owner == 'mybatis' && ! contains(toJSON(github.event.head_commit.message), '[maven-release-plugin]') 17 | runs-on: ubuntu-latest 18 | timeout-minutes: 30 19 | steps: 20 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 21 | - name: Setup Java 22 | uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5 23 | with: 24 | cache: maven 25 | distribution: temurin 26 | java-version: 25 27 | - name: Deploy to Sonatype 28 | run: ./mvnw deploy --batch-mode --no-transfer-progress --settings ./.mvn/settings.xml --show-version -Dlicense.skip=true -DskipTests 29 | env: 30 | CI_DEPLOY_USERNAME: ${{ secrets.CI_DEPLOY_USERNAME }} 31 | CI_DEPLOY_PASSWORD: ${{ secrets.CI_DEPLOY_PASSWORD }} 32 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/mapper/AnnotatedMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.mapper; 17 | 18 | import org.springframework.stereotype.Component; 19 | 20 | // annotated interface for MapperScannerPostProcessor tests 21 | // ensures annotated classes are loaded 22 | @Component 23 | public interface AnnotatedMapper { 24 | void method(); 25 | 26 | default String test() { 27 | return Thread.currentThread().getName(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/config/MyBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.config; 17 | 18 | public class MyBean { 19 | private String id; 20 | private String name; 21 | 22 | public MyBean(String id) { 23 | this.id = id; 24 | } 25 | 26 | public String getId() { 27 | return id; 28 | } 29 | 30 | public void setName(String name) { 31 | this.name = name; 32 | } 33 | 34 | public String getName() { 35 | return name; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/sample/SampleMapperTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.sample; 17 | 18 | import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; 19 | 20 | /** 21 | * Example of MyBatis-Spring integration with a DAO created by MapperFactoryBean. 22 | */ 23 | @SpringJUnitConfig(locations = { "classpath:org/mybatis/spring/sample/config/applicationContext-mapper.xml" }) 24 | class SampleMapperTest extends AbstractSampleTest { 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/annotation/MyBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2023 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.annotation; 17 | 18 | public class MyBean { 19 | private String id; 20 | private String name; 21 | 22 | public MyBean(String id) { 23 | this.id = id; 24 | } 25 | 26 | public String getId() { 27 | return id; 28 | } 29 | 30 | public void setName(String name) { 31 | this.name = name; 32 | } 33 | 34 | public String getName() { 35 | return name; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/mapper/ScopedProxyMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.mapper; 17 | 18 | import org.apache.ibatis.annotations.Mapper; 19 | import org.springframework.context.annotation.Scope; 20 | import org.springframework.context.annotation.ScopedProxyMode; 21 | 22 | @Mapper 23 | @Scope(scopeName = "thread", proxyMode = ScopedProxyMode.TARGET_CLASS) 24 | public interface ScopedProxyMapper { 25 | default String test() { 26 | return "test"; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/sample/SampleScannerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.sample; 17 | 18 | import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; 19 | 20 | /** 21 | * Example of MyBatis-Spring integration with a DAO configured via MapperScannerConfigurer. 22 | */ 23 | @SpringJUnitConfig(locations = { "classpath:org/mybatis/spring/sample/config/applicationContext-scanner.xml" }) 24 | class SampleScannerTest extends AbstractSampleTest { 25 | } 26 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/submitted/autowire/BarMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 24 | 25 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/sample/SampleNamespaceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.sample; 17 | 18 | import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; 19 | 20 | /** 21 | * Example of MyBatis-Spring integration with a DAO configured via MapperScannerConfigurer. 22 | */ 23 | @SpringJUnitConfig(locations = { "classpath:org/mybatis/spring/sample/config/applicationContext-namespace.xml" }) 24 | class SampleNamespaceTest extends AbstractSampleTest { 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/annotation/mapper/ds1/AppConfigWithDefaultMapperScans.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.annotation.mapper.ds1; 17 | 18 | import org.mybatis.spring.annotation.MapperScan; 19 | import org.mybatis.spring.annotation.MapperScans; 20 | import org.springframework.context.annotation.Configuration; 21 | 22 | @Configuration 23 | @MapperScans({ @MapperScan, @MapperScan("org.mybatis.spring.annotation.mapper.ds2") }) 24 | public class AppConfigWithDefaultMapperScans { 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/filter/customfilter/AnnoTypeFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.filter.customfilter; 17 | 18 | import java.lang.annotation.Documented; 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | @Retention(RetentionPolicy.RUNTIME) 25 | @Target({ ElementType.TYPE }) 26 | @Documented 27 | public @interface AnnoTypeFilter { 28 | } 29 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/sample/db/database-schema.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- Copyright 2010-2024 the original author or authors. 3 | -- 4 | -- Licensed under the Apache License, Version 2.0 (the "License"); 5 | -- you may not use this file except in compliance with the License. 6 | -- You may obtain a copy of the License at 7 | -- 8 | -- https://www.apache.org/licenses/LICENSE-2.0 9 | -- 10 | -- Unless required by applicable law or agreed to in writing, software 11 | -- distributed under the License is distributed on an "AS IS" BASIS, 12 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | -- See the License for the specific language governing permissions and 14 | -- limitations under the License. 15 | -- 16 | 17 | drop table users if exists; 18 | create table users ( 19 | id varchar(80) not null, 20 | name varchar(80) not null, 21 | constraint pk_user primary key (id) 22 | ); 23 | 24 | drop table persons if exists; 25 | create table persons ( 26 | person_id integer identity not null primary key, 27 | first_name varchar(20), 28 | last_name varchar(20), 29 | operation_by varchar(64), 30 | operation_at timestamp 31 | ); 32 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: Java CI 2 | 3 | on: [workflow_dispatch, push, pull_request] 4 | 5 | permissions: read-all 6 | 7 | concurrency: 8 | group: ${{ github.workflow }}-${{ github.ref }} 9 | cancel-in-progress: true 10 | 11 | jobs: 12 | test: 13 | runs-on: ${{ matrix.os }} 14 | timeout-minutes: 30 15 | strategy: 16 | matrix: 17 | cache: [maven] 18 | distribution: [temurin] 19 | java: [21, 25, 26-ea] 20 | os: [macos-latest, ubuntu-latest, windows-latest] 21 | fail-fast: false 22 | max-parallel: 6 23 | name: Test JDK ${{ matrix.java }}, ${{ matrix.os }} 24 | 25 | steps: 26 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 27 | - name: Setup Java ${{ matrix.java }} ${{ matrix.distribution }} 28 | uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5 29 | with: 30 | cache: ${{ matrix.cache }} 31 | distribution: ${{ matrix.distribution }} 32 | java-version: ${{ matrix.java }} 33 | - name: Test with Maven 34 | run: ./mvnw test --batch-mode --no-transfer-progress --show-version -D"license.skip=true" 35 | -------------------------------------------------------------------------------- /src/site/zh_CN/markdown/using-api.md: -------------------------------------------------------------------------------- 1 | 2 | # 使用 MyBatis API 3 | 4 | 使用 MyBatis-Spring,你可以继续直接使用 MyBatis 的 API。只需简单地使用 `SqlSessionFactoryBean` 在 Spring 中创建一个 `SqlSessionFactory`,然后按你的方式在代码中使用工厂即可。 5 | 6 | ```java 7 | public class UserDaoImpl implements UserDao { 8 | // SqlSessionFactory 一般会由 SqlSessionDaoSupport 进行设置 9 | private final SqlSessionFactory sqlSessionFactory; 10 | 11 | public UserDaoImpl(SqlSessionFactory sqlSessionFactory) { 12 | this.sqlSessionFactory = sqlSessionFactory; 13 | } 14 | 15 | public User getUser(String userId) { 16 | // 注意对标准 MyBatis API 的使用 - 手工打开和关闭 session 17 | try (SqlSession session = sqlSessionFactory.openSession()) { 18 | return session.selectOne("org.mybatis.spring.sample.mapper.UserMapper.getUser", userId); 19 | } 20 | } 21 | } 22 | ``` 23 | 24 | **小心使用**此选项,错误地使用会产生运行时错误,更糟糕地,会产生数据一致性的问题。直接使用 API 时,注意以下弊端: 25 | 26 | * 它不会参与到 Spring 的事务管理之中。 27 | * 如果 `SqlSession` 使用与 Spring 事务管理器使用的相同 `DataSource`,并且有进行中的事务,代码**将**会抛出异常。 28 | * MyBatis 的 `DefaultSqlSession` 是线程不安全的。如果在 bean 中注入了它,**将**会发生错误。 29 | * 使用 `DefaultSqlSession` 创建的映射器也不是线程安全的。如果你将它们注入到 bean 中,**将**会发生错误。 30 | * 你必须确保总是在 finally 块中来关闭 `SqlSession`。 31 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/batch/db/database-test-data.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- Copyright 2010-2024 the original author or authors. 3 | -- 4 | -- Licensed under the Apache License, Version 2.0 (the "License"); 5 | -- you may not use this file except in compliance with the License. 6 | -- You may obtain a copy of the License at 7 | -- 8 | -- https://www.apache.org/licenses/LICENSE-2.0 9 | -- 10 | -- Unless required by applicable law or agreed to in writing, software 11 | -- distributed under the License is distributed on an "AS IS" BASIS, 12 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | -- See the License for the specific language governing permissions and 14 | -- limitations under the License. 15 | -- 16 | 17 | insert into employees VALUES ( 1, 'Pocoyo' , 1000, 's1'); 18 | insert into employees VALUES ( 1, 'Pocoyo' , 1000, 's2'); 19 | insert into employees VALUES ( 2, 'Pato' , 2000, 's1'); 20 | insert into employees VALUES ( 2, 'Pato' , 2000, 's2'); 21 | insert into employees VALUES ( 3, 'Eli' , 3000, 's1'); 22 | insert into employees VALUES ( 3, 'Eli' , 3000, 's2'); 23 | insert into employees VALUES ( 3, 'Eli' , 3000, 's3'); 24 | insert into employees VALUES ( 4, 'Valentina' , 4000, 's1'); 25 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/mapper/AnnotatedMapperOnPropertyCondition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.mapper; 17 | 18 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 19 | import org.springframework.stereotype.Component; 20 | 21 | // annotated interface for MapperScannerPostProcessor tests 22 | // ensures annotated classes are loaded on property condition 23 | @Component 24 | @ConditionalOnProperty(prefix = "mapper", value = "condition", havingValue = "true") 25 | public interface AnnotatedMapperOnPropertyCondition { 26 | void method(); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/spring/config/NamespaceHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.config; 17 | 18 | import org.springframework.beans.factory.xml.NamespaceHandlerSupport; 19 | 20 | /** 21 | * Namespace handler for the MyBatis namespace. 22 | * 23 | * @author Lishu Luo 24 | * 25 | * @see MapperScannerBeanDefinitionParser 26 | * 27 | * @since 1.2.0 28 | */ 29 | public class NamespaceHandler extends NamespaceHandlerSupport { 30 | 31 | @Override 32 | public void init() { 33 | registerBeanDefinitionParser("scan", new MapperScannerBeanDefinitionParser()); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/sample/SampleJobJavaConfigTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.sample; 17 | 18 | import org.mybatis.spring.sample.config.SampleJobConfig; 19 | import org.springframework.batch.test.context.SpringBatchTest; 20 | import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; 21 | 22 | @SpringJUnitConfig({ SampleJobConfig.class, AbstractSampleJobTest.LocalContext.class }) 23 | @SpringBatchTest 24 | class SampleJobJavaConfigTest extends AbstractSampleJobTest { 25 | @Override 26 | protected String getExpectedOperationBy() { 27 | return "batch_java_config_user"; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/sample/mapper/PersonMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 22 | 23 | 24 | 25 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/submitted/xa/User.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.submitted.xa; 17 | 18 | public class User { 19 | 20 | private Integer id; 21 | private String name; 22 | 23 | public User() { 24 | } 25 | 26 | public User(Integer id, String name) { 27 | this.id = id; 28 | this.name = name; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public void setName(String name) { 36 | this.name = name; 37 | } 38 | 39 | public Integer getId() { 40 | return this.id; 41 | } 42 | 43 | public void setId(Integer id) { 44 | this.id = id; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/sample/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 22 | 23 | 24 | 25 | 28 | 29 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /.github/workflows/site.yaml: -------------------------------------------------------------------------------- 1 | name: Site 2 | 3 | on: 4 | push: 5 | branches: 6 | - site 7 | 8 | permissions: 9 | contents: write 10 | 11 | concurrency: 12 | group: ${{ github.workflow }}-${{ github.ref }} 13 | cancel-in-progress: true 14 | 15 | jobs: 16 | build: 17 | if: github.repository_owner == 'mybatis' && ! contains(toJSON(github.event.head_commit.message), '[maven-release-plugin]') 18 | runs-on: ubuntu-latest 19 | timeout-minutes: 60 20 | steps: 21 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 22 | - name: Setup Java 23 | uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5 24 | with: 25 | cache: maven 26 | distribution: temurin 27 | java-version: 25 28 | - name: Build site 29 | run: ./mvnw site site:stage --batch-mode --no-transfer-progress --settings ./.mvn/settings.xml --show-version -Dlicense.skip=true -DskipTests 30 | env: 31 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 32 | NVD_API_KEY: ${{ secrets.NVD_API_KEY }} 33 | - name: Deploy Site to gh-pages 34 | uses: JamesIves/github-pages-deploy-action@9d877eea73427180ae43cf98e8914934fe157a1a # v4 35 | with: 36 | branch: gh-pages 37 | folder: target/staging 38 | -------------------------------------------------------------------------------- /scripts/get_latest_version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2010-2022 the original author or authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | 19 | targetArtifact=$1 20 | targetMinorVersion=$2 21 | majorVersion=${targetMinorVersion%.*} 22 | minorVersion=${targetMinorVersion#*.} 23 | while read -r line; do 24 | maintenanceVersion=${line#${targetMinorVersion}.} && maintenanceVersion=${maintenanceVersion%%.*} 25 | maintenanceVersions="${maintenanceVersions}${maintenanceVersion}"$'\n' 26 | done<${majorVersion}\.${minorVersion}\.[0-9]*") 28 | END 29 | echo "${targetMinorVersion}.$(echo "${maintenanceVersions}" | sort -n | tail -n 1).RELEASE" 30 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yaml: -------------------------------------------------------------------------------- 1 | name: "CodeQL" 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | schedule: 9 | - cron: '43 10 * * 2' 10 | 11 | concurrency: 12 | group: ${{ github.workflow }}-${{ github.ref }} 13 | cancel-in-progress: true 14 | 15 | jobs: 16 | analyze: 17 | name: Analyze 18 | runs-on: 'ubuntu-latest' 19 | timeout-minutes: 30 20 | permissions: 21 | actions: read 22 | contents: read 23 | security-events: write 24 | 25 | steps: 26 | - name: Checkout 27 | uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 28 | 29 | - name: Setup Java 30 | uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5 31 | with: 32 | cache: maven 33 | distribution: 'temurin' 34 | java-version: 25 35 | 36 | - name: Initialize CodeQL 37 | uses: github/codeql-action/init@5d4e8d1aca955e8d8589aabd499c5cae939e33c7 # v4 38 | with: 39 | queries: +security-and-quality 40 | 41 | - name: Autobuild 42 | uses: github/codeql-action/autobuild@5d4e8d1aca955e8d8589aabd499c5cae939e33c7 # v4 43 | 44 | - name: Perform CodeQL Analysis 45 | uses: github/codeql-action/analyze@5d4e8d1aca955e8d8589aabd499c5cae939e33c7 # v4 46 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/filter/customfilter/CustomTypeFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.filter.customfilter; 17 | 18 | import java.io.IOException; 19 | 20 | import org.springframework.core.type.classreading.MetadataReader; 21 | import org.springframework.core.type.classreading.MetadataReaderFactory; 22 | import org.springframework.core.type.filter.TypeFilter; 23 | 24 | public class CustomTypeFilter implements TypeFilter { 25 | @Override 26 | public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException { 27 | return metadataReader.getClassMetadata().getClassName().contains("datasource2"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/sample/batch/UserToPersonItemProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2025 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.sample.batch; 17 | 18 | import org.mybatis.spring.sample.domain.Person; 19 | import org.mybatis.spring.sample.domain.User; 20 | import org.springframework.batch.infrastructure.item.ItemProcessor; 21 | 22 | public class UserToPersonItemProcessor implements ItemProcessor { 23 | 24 | @Override 25 | public Person process(final User user) throws Exception { 26 | final var names = user.getName().split(" "); 27 | if (names.length == 1) { 28 | return new Person(names[0], null); 29 | } 30 | return new Person(names[0], names[1]); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/site/ko/markdown/using-api.md: -------------------------------------------------------------------------------- 1 | 2 | # MyBatis API 사용하기 3 | 4 | MyBatis-Spring 연동 모듈을 사용해도 계속해서 MyBatis API를 직접 사용할 수 있다. `SqlSessionFactoryBean`을 사용해서 스프링에서 `SqlSessionFactory`를 생성하고 팩토리를 사용하면 된다. 5 | 6 | ```java 7 | public class UserDaoImpl implements UserDao { 8 | // SqlSessionFactory would normally be set by SqlSessionDaoSupport 9 | private final SqlSessionFactory sqlSessionFactory; 10 | 11 | public UserDaoImpl(SqlSessionFactory sqlSessionFactory) { 12 | this.sqlSessionFactory = sqlSessionFactory; 13 | } 14 | 15 | public User getUser(String userId) { 16 | // note standard MyBatis API usage - opening and closing the session manually 17 | try (SqlSession session = sqlSessionFactory.openSession()) { 18 | return session.selectOne("org.mybatis.spring.sample.mapper.UserMapper.getUser", userId); 19 | } 20 | } 21 | } 22 | ``` 23 | 24 | 이 방법은 **신중히** 사용하자. 왜냐하면 잘못 사용하면 런타임 에러나 데이터 문제 등을 야기할 수 있기 때문이다. API를 직접 사용할 때는 다음의 규칙들에 유의해야 한다. 25 | 26 | * 스프링 트랜잭션에 **속하지 않고** 별도의 트랜잭션에서 동작한다. 27 | * `SqlSession`이 스프링 트랜잭션 관리자가 사용하는 `DataSource`를 사용하고 이미 트랜잭션이 동작하고 있다면 이 코드는 예외를 **발생시킬 것이다**. 28 | * 마이바티스의 `DefaultSqlSession`은 쓰레드에 안전하지 않다. 빈에 이 객체를 주입하면 아마도 에러를 **발생시킬 수 있다**. 29 | * `DefaultSqlSession`을 사용해서 생성한 매퍼 또한 쓰레드에 안전하지 않다. 이렇게 만든 매퍼를 빈에 주입하면 에러를 **발생시킬 수 있다**. 30 | * `SqlSession`은 **항상** 마지막에 `close()` 메서드를 호출해야 한다. 31 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/sample/SampleBatchTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.sample; 17 | 18 | import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; 19 | 20 | /** 21 | * Example of MyBatis-Spring batch integration usage. 22 | */ 23 | @SpringJUnitConfig(locations = { "classpath:org/mybatis/spring/sample/config/applicationContext-batch.xml" }) 24 | class SampleBatchTest extends AbstractSampleTest { 25 | // Note this does not actually test batch functionality since FooService 26 | // only calls one DAO method. This class and associated Spring context 27 | // simply show that no implementation changes are needed to enable 28 | // different MyBatis configurations. 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/sample/service/BarService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.sample.service; 17 | 18 | import org.mybatis.spring.sample.dao.UserDao; 19 | import org.mybatis.spring.sample.domain.User; 20 | import org.springframework.transaction.annotation.Transactional; 21 | 22 | /** 23 | * BarService simply receives a userId and uses a dao to get a record from the database. 24 | */ 25 | @Transactional 26 | public class BarService { 27 | 28 | private final UserDao userDao; 29 | 30 | public BarService(UserDao userDao) { 31 | this.userDao = userDao; 32 | } 33 | 34 | public User doSomeBusinessStuff(String userId) { 35 | return this.userDao.getUser(userId); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/site/resources/css/site.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /* 17 | * when new flags are needed, take them from 18 | * 19 | * https://www.printableworldflags.com/flag-icon 20 | * 21 | * that are free for any kind of usage 22 | */ 23 | 24 | ul.i18n {list-style-type:none;} 25 | li.en {background: url('../images/en.png') left no-repeat;padding-left: 32px; margin: 10px} 26 | li.es {background: url('../images/es.png') left no-repeat;padding-left: 32px; margin: 10px} 27 | li.ja {background: url('../images/ja.png') left no-repeat;padding-left: 32px; margin: 10px} 28 | li.zh {background: url('../images/zh.png') left no-repeat;padding-left: 32px; margin: 10px} 29 | li.ko {background: url('../images/ko.png') left no-repeat;padding-left: 32px; margin: 10px} 30 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/sample/service/FooService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.sample.service; 17 | 18 | import org.mybatis.spring.sample.domain.User; 19 | import org.mybatis.spring.sample.mapper.UserMapper; 20 | import org.springframework.transaction.annotation.Transactional; 21 | 22 | /** 23 | * FooService simply receives a userId and uses a mapper to get a record from the database. 24 | */ 25 | @Transactional 26 | public class FooService { 27 | 28 | private final UserMapper userMapper; 29 | 30 | public FooService(UserMapper userMapper) { 31 | this.userMapper = userMapper; 32 | } 33 | 34 | public User doSomeBusinessStuff(String userId) { 35 | return this.userMapper.getUser(userId); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/config/name-generator.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 25 | 26 | 28 | 29 | -------------------------------------------------------------------------------- /src/site/ja/markdown/using-api.md: -------------------------------------------------------------------------------- 1 | 2 | # MyBatis API の使用 3 | 4 | MyBatis-Spring を使っている場合でも、直接 MyBatis API を呼び出すことができます。 5 | Spring の設定で `SqlSessionFactoryBean` を使って `SqlSessionFactory` を生成すれば、コード内で使用することができます。 6 | 7 | ```java 8 | public class UserDaoImpl implements UserDao { 9 | // SqlSessionFactory would normally be set by SqlSessionDaoSupport 10 | private final SqlSessionFactory sqlSessionFactory; 11 | 12 | public UserDaoImpl(SqlSessionFactory sqlSessionFactory) { 13 | this.sqlSessionFactory = sqlSessionFactory; 14 | } 15 | 16 | public User getUser(String userId) { 17 | // note standard MyBatis API usage - opening and closing the session manually 18 | try (SqlSession session = sqlSessionFactory.openSession()) { 19 | return session.selectOne("org.mybatis.spring.sample.mapper.UserMapper.getUser", userId); 20 | } 21 | } 22 | } 23 | ``` 24 | 25 | この方法を使う場合は注意が必要です。なぜなら、誤った使い方をすると実行時エラーや、最悪の場合データの不整合といった問題を生じる可能性があるからです。 26 | MyBatis API を直接使用する場合、次のような点に注意してください。 27 | 28 | * API の呼び出しは Spring で管理されているトランザクション内では実行されません。 29 | * `SqlSession` が Spring のトランザクションマネージャーが使っているのと同じ `DataSource` を使っていて、既に進行中のトランザクションが存在している場合、このコードは例外を投げます。 30 | * MyBatis の `DefaultSqlSession` はスレッドセーフではありません。もしあなたの Bean に注入した場合、エラーが発生します。 31 | * `DefaultSqlSession` を使って生成した Mapper もスレッドセーフとはなりません。もしあなたの Bean に注入した場合、エラーが発生します。 32 | * `SqlSession` は常に finally ブロックでクローズする必要があります。 33 | -------------------------------------------------------------------------------- /src/site/resources/es/css/site.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /* 17 | * when new flags are needed, take them from 18 | * 19 | * https://www.printableworldflags.com/flag-icon 20 | * 21 | * that are free for any kind of usage 22 | */ 23 | 24 | ul.i18n {list-style-type:none;} 25 | li.en {background: url('../../images/en.png') left no-repeat;padding-left: 32px; margin: 10px} 26 | li.es {background: url('../../images/es.png') left no-repeat;padding-left: 32px; margin: 10px} 27 | li.ja {background: url('../../images/ja.png') left no-repeat;padding-left: 32px; margin: 10px} 28 | li.zh {background: url('../../images/zh.png') left no-repeat;padding-left: 32px; margin: 10px} 29 | li.ko {background: url('../../images/ko.png') left no-repeat;padding-left: 32px; margin: 10px} 30 | -------------------------------------------------------------------------------- /src/site/resources/ja/css/site.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /* 17 | * when new flags are needed, take them from 18 | * 19 | * https://www.printableworldflags.com/flag-icon 20 | * 21 | * that are free for any kind of usage 22 | */ 23 | 24 | ul.i18n {list-style-type:none;} 25 | li.en {background: url('../../images/en.png') left no-repeat;padding-left: 32px; margin: 10px} 26 | li.es {background: url('../../images/es.png') left no-repeat;padding-left: 32px; margin: 10px} 27 | li.ja {background: url('../../images/ja.png') left no-repeat;padding-left: 32px; margin: 10px} 28 | li.zh {background: url('../../images/zh.png') left no-repeat;padding-left: 32px; margin: 10px} 29 | li.ko {background: url('../../images/ko.png') left no-repeat;padding-left: 32px; margin: 10px} 30 | -------------------------------------------------------------------------------- /src/site/resources/ko/css/site.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /* 17 | * when new flags are needed, take them from 18 | * 19 | * https://www.printableworldflags.com/flag-icon 20 | * 21 | * that are free for any kind of usage 22 | */ 23 | 24 | ul.i18n {list-style-type:none;} 25 | li.en {background: url('../../images/en.png') left no-repeat;padding-left: 32px; margin: 10px} 26 | li.es {background: url('../../images/es.png') left no-repeat;padding-left: 32px; margin: 10px} 27 | li.ja {background: url('../../images/ja.png') left no-repeat;padding-left: 32px; margin: 10px} 28 | li.zh {background: url('../../images/zh.png') left no-repeat;padding-left: 32px; margin: 10px} 29 | li.ko {background: url('../../images/ko.png') left no-repeat;padding-left: 32px; margin: 10px} 30 | -------------------------------------------------------------------------------- /src/site/resources/zh_CN/css/site.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /* 17 | * when new flags are needed, take them from 18 | * 19 | * https://www.printableworldflags.com/flag-icon 20 | * 21 | * that are free for any kind of usage 22 | */ 23 | 24 | ul.i18n {list-style-type:none;} 25 | li.en {background: url('../../images/en.png') left no-repeat;padding-left: 32px; margin: 10px} 26 | li.es {background: url('../../images/es.png') left no-repeat;padding-left: 32px; margin: 10px} 27 | li.ja {background: url('../../images/ja.png') left no-repeat;padding-left: 32px; margin: 10px} 28 | li.zh {background: url('../../images/zh.png') left no-repeat;padding-left: 32px; margin: 10px} 29 | li.ko {background: url('../../images/ko.png') left no-repeat;padding-left: 32px; margin: 10px} 30 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/config/mapper-factory-bean-class.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 25 | 26 | 28 | 29 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/sample/AbstractSampleTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.sample; 17 | 18 | import static org.assertj.core.api.Assertions.assertThat; 19 | 20 | import org.junit.jupiter.api.Test; 21 | import org.mybatis.spring.sample.service.FooService; 22 | import org.springframework.beans.factory.annotation.Autowired; 23 | import org.springframework.test.annotation.DirtiesContext; 24 | 25 | @DirtiesContext 26 | abstract class AbstractSampleTest { 27 | 28 | @Autowired 29 | protected FooService fooService; 30 | 31 | @Test 32 | final void testFooService() { 33 | var user = this.fooService.doSomeBusinessStuff("u1"); 34 | assertThat(user).isNotNull(); 35 | assertThat(user.getName()).isEqualTo("Pocoyo"); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/scan/ScanClass1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.scan; 17 | 18 | import java.util.function.Supplier; 19 | 20 | import org.apache.ibatis.jdbc.SQL; 21 | 22 | public class ScanClass1 { 23 | 24 | public static class StaticInnerClass { 25 | 26 | } 27 | 28 | public class InnerClass { 29 | 30 | } 31 | 32 | public enum InnerEnum { 33 | 34 | } 35 | 36 | public @interface InnerAnnotation { 37 | 38 | } 39 | 40 | public String createSqlUsingAnonymousClass() { 41 | return new SQL() { 42 | { 43 | SELECT("a"); 44 | FROM("test1"); 45 | } 46 | }.toString(); 47 | } 48 | 49 | public Supplier createSqlSupplier() { 50 | return () -> "SELECT a FROM test1"; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/scan/ScanClass2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.scan; 17 | 18 | import java.util.function.Supplier; 19 | 20 | import org.apache.ibatis.jdbc.SQL; 21 | 22 | public class ScanClass2 { 23 | 24 | public static class StaticInnerClass { 25 | 26 | } 27 | 28 | public class InnerClass { 29 | 30 | } 31 | 32 | public enum InnerEnum { 33 | 34 | } 35 | 36 | public @interface InnerAnnotation { 37 | 38 | } 39 | 40 | public String createSqlUsingAnonymousClass() { 41 | return new SQL() { 42 | { 43 | SELECT("a"); 44 | FROM("test2"); 45 | } 46 | }.toString(); 47 | } 48 | 49 | public Supplier createSqlSupplier() { 50 | return () -> "SELECT a FROM test2"; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/sample/dao/UserDaoImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.sample.dao; 17 | 18 | import org.mybatis.spring.sample.domain.User; 19 | import org.mybatis.spring.support.SqlSessionDaoSupport; 20 | 21 | /** 22 | * This DAO extends SqlSessionDaoSupport and uses a Spring managed SqlSession instead of the MyBatis one. SqlSessions 23 | * are handled by Spring so you don't need to open/close/commit/rollback. MyBatis exceptions are translated to Spring 24 | * Data Exceptions. 25 | */ 26 | public class UserDaoImpl extends SqlSessionDaoSupport implements UserDao { 27 | 28 | @Override 29 | public User getUser(String userId) { 30 | return getSqlSession().selectOne("org.mybatis.spring.sample.mapper.UserMapper.getUser", userId); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/mybatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/sample/SampleEnableTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.sample; 17 | 18 | import org.mybatis.spring.annotation.MapperScan; 19 | import org.springframework.context.annotation.Configuration; 20 | import org.springframework.context.annotation.ImportResource; 21 | import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; 22 | 23 | /** 24 | * Test to ensure that the {@link MapperScan} annotation works as expected. 25 | * 26 | * @since 1.2.0 27 | */ 28 | @SpringJUnitConfig 29 | class SampleEnableTest extends AbstractSampleTest { 30 | 31 | @Configuration 32 | @ImportResource("classpath:org/mybatis/spring/sample/config/applicationContext-infrastructure.xml") 33 | @MapperScan("org.mybatis.spring.sample.mapper") 34 | static class AppConfig { 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/TestMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 22 | 23 | 24 | 27 | 28 | 1 29 | 30 | 31 | 34 | 35 | 36 | INSERT #{test} INTO test 37 | 38 | 39 | 40 | INSERT fail 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/sample/domain/User.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.sample.domain; 17 | 18 | /** 19 | * A simple bean that holds User info. 20 | */ 21 | public class User { 22 | 23 | private String id; 24 | 25 | private String name; 26 | 27 | public String getId() { 28 | return id; 29 | } 30 | 31 | public void setId(String id) { 32 | this.id = id; 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public void setName(String name) { 40 | this.name = name; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | var buf = new StringBuilder(30); 46 | buf.append("{"); 47 | buf.append(id); 48 | buf.append(", "); 49 | buf.append(name); 50 | buf.append("}"); 51 | return buf.toString(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/submitted/autowire/AutowireTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.submitted.autowire; 17 | 18 | import static org.assertj.core.api.Assertions.assertThat; 19 | 20 | import org.junit.jupiter.api.Test; 21 | import org.springframework.context.support.ClassPathXmlApplicationContext; 22 | 23 | class AutowireTest { 24 | 25 | @Test 26 | void shouldReturnMapper() { 27 | try (var context = new ClassPathXmlApplicationContext( 28 | "classpath:org/mybatis/spring/submitted/autowire/spring.xml")) { 29 | 30 | var fooMapper = (FooMapper) context.getBean("fooMapper"); 31 | assertThat(fooMapper).isNotNull(); 32 | fooMapper.executeFoo(); 33 | 34 | var barMapper = (BarMapper) context.getBean("barMapper"); 35 | assertThat(barMapper).isNotNull(); 36 | barMapper.executeBar(); 37 | } 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/sample/SampleJobXmlConfigTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.sample; 17 | 18 | import org.springframework.batch.test.context.SpringBatchTest; 19 | import org.springframework.context.annotation.Configuration; 20 | import org.springframework.context.annotation.ImportResource; 21 | import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; 22 | 23 | @SpringJUnitConfig({ AbstractSampleJobTest.LocalContext.class, SampleJobXmlConfigTest.LocalContext.class }) 24 | @SpringBatchTest 25 | class SampleJobXmlConfigTest extends AbstractSampleJobTest { 26 | 27 | @Override 28 | protected String getExpectedOperationBy() { 29 | return "batch_xml_config_user"; 30 | } 31 | 32 | @ImportResource("classpath:org/mybatis/spring/sample/config/applicationContext-job.xml") 33 | @Configuration 34 | static class LocalContext { 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/sample/domain/Person.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.sample.domain; 17 | 18 | public class Person { 19 | 20 | private String lastName; 21 | private String firstName; 22 | 23 | public Person() { 24 | } 25 | 26 | public Person(String firstName, String lastName) { 27 | this.firstName = firstName; 28 | this.lastName = lastName; 29 | } 30 | 31 | public void setFirstName(String firstName) { 32 | this.firstName = firstName; 33 | } 34 | 35 | public String getFirstName() { 36 | return firstName; 37 | } 38 | 39 | public String getLastName() { 40 | return lastName; 41 | } 42 | 43 | public void setLastName(String lastName) { 44 | this.lastName = lastName; 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return "firstName: " + firstName + ", lastName: " + lastName; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /.github/workflows/sonar.yaml: -------------------------------------------------------------------------------- 1 | name: SonarCloud 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | permissions: read-all 9 | 10 | concurrency: 11 | group: ${{ github.workflow }}-${{ github.ref }} 12 | cancel-in-progress: true 13 | 14 | env: 15 | SONAR_ORGANIZATION: mybatis 16 | SONAR_PROJECT_KEY: spring 17 | 18 | jobs: 19 | build: 20 | if: github.repository_owner == 'mybatis' 21 | runs-on: ubuntu-latest 22 | timeout-minutes: 30 23 | steps: 24 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 25 | with: 26 | # Disabling shallow clone is recommended for improving relevancy of reporting 27 | fetch-depth: 0 28 | - name: Setup Java 29 | uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5 30 | with: 31 | cache: maven 32 | distribution: temurin 33 | java-version: 25 34 | - name: Set SONAR_SCANNER_JAVA_OPTS 35 | run: echo "SONAR_SCANNER_JAVA_OPTS=-Xmx512m" >> ${GITHUB_ENV} 36 | - name: Analyze with SonarCloud 37 | run: ./mvnw verify jacoco:report sonar:sonar --batch-mode --no-transfer-progress --show-version -Dlicense.skip=true -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=${{ env.SONAR_ORGANIZATION }} -Dsonar.projectKey=${{ env.SONAR_ORGANIZATION }}_${{ env.SONAR_PROJECT_KEY }} -Dsonar.scanner.skipJreProvisioning=true -Dsonar.token=${{ env.SONAR_TOKEN }} 38 | env: 39 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 40 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | MyBatis Spring Adapter 2 | ====================== 3 | 4 | [![Java CI](https://github.com/mybatis/spring/actions/workflows/ci.yaml/badge.svg)](https://github.com/mybatis/spring/actions/workflows/ci.yaml) 5 | [![Coverage Status](https://coveralls.io/repos/mybatis/spring/badge.svg?branch=master&service=github)](https://coveralls.io/github/mybatis/spring?branch=master) 6 | [![Maven central](https://maven-badges.herokuapp.com/maven-central/org.mybatis/mybatis-spring/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.mybatis/mybatis-spring) 7 | [![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/https/oss.sonatype.org/org.mybatis/mybatis-spring.svg)](https://oss.sonatype.org/content/repositories/snapshots/org/mybatis/mybatis-spring/) 8 | [![License](https://img.shields.io/:license-apache-brightgreen.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) 9 | 10 | ![mybatis-spring](https://mybatis.org/images/mybatis-logo.png) 11 | 12 | MyBatis-Spring adapter is an easy-to-use [Spring Framework](https://github.com/spring-projects/spring-framework) bridge for [MyBatis](https://github.com/mybatis/mybatis-3) sql mapping framework. 13 | 14 | Supported Versions 15 | ------------------ 16 | 17 | - master - Support for Spring 7 and Spring Batch 6 18 | - 3.0.x - Support for Spring 6 and Spring Batch 5 19 | - 2.1.x - Maintenance for Spring 5 and Spring Batch 4 20 | 21 | Essentials 22 | ---------- 23 | 24 | * [See the published docs](https://mybatis.org/spring/) 25 | * [See the snapshot docs](src/site/markdown) (Note: may contain explanation of unreleased features) 26 | -------------------------------------------------------------------------------- /.github/workflows/coveralls.yaml: -------------------------------------------------------------------------------- 1 | name: Coveralls 2 | 3 | on: [push, pull_request] 4 | 5 | permissions: read-all 6 | 7 | concurrency: 8 | group: ${{ github.workflow }}-${{ github.ref }} 9 | cancel-in-progress: true 10 | 11 | jobs: 12 | coveralls: 13 | if: github.repository_owner == 'mybatis' 14 | runs-on: ubuntu-latest 15 | timeout-minutes: 30 16 | steps: 17 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 18 | - name: Setup Java 19 | uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5 20 | with: 21 | cache: maven 22 | distribution: temurin 23 | java-version: 25 24 | - name: Run the build 25 | run: ./mvnw test --batch-mode --no-transfer-progress --quiet --show-version -Dlicense.skip=true 26 | - name: Report Coverage to Coveralls for Pull Requests 27 | if: github.event_name == 'pull_request' 28 | run: ./mvnw generate-sources jacoco:report coveralls:report --batch-mode --no-transfer-progress -DpullRequest=${{ env.PR_NUMBER }} -DrepoToken=${{ env.GITHUB_TOKEN }} -DserviceName=github 29 | env: 30 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 31 | PR_NUMBER: ${{ github.event.number }} 32 | - name: Report Coverage to Coveralls for General Push 33 | if: github.event_name == 'push' 34 | run: ./mvnw generate-sources jacoco:report coveralls:report --batch-mode --no-transfer-progress -DrepoToken=${{ env.GITHUB_TOKEN }} -DserviceName=github 35 | env: 36 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 37 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/asyncsynchronization/SqlSessionTemplateAsyncAfterCompletionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.asyncsynchronization; 17 | 18 | import org.jboss.byteman.contrib.bmunit.BMRule; 19 | import org.junit.jupiter.api.Disabled; 20 | import org.mybatis.spring.SqlSessionTemplateTest; 21 | 22 | /** 23 | * The same test as original but afterCompletion is being called on a separate thread 24 | * 25 | * @author Alex Rykov 26 | */ 27 | @Disabled // FIXME: Enable after migrate BMUnitRunner to BMUnitExtension 28 | // @ExtendWith(BMUnitRunner.class) 29 | @BMRule(name = "proxy synchronizations", targetClass = "TransactionSynchronizationManager", targetMethod = "registerSynchronization(TransactionSynchronization)", helper = "org.mybatis.spring.asyncsynchronization.AsyncAfterCompletionHelper", action = "$1=createSynchronizationWithAsyncAfterComplete($1)") 30 | class SqlSessionTemplateAsyncAfterCompletionTest extends SqlSessionTemplateTest { 31 | } 32 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/config/lazy.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/logging/LoggerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2025 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.logging; 17 | 18 | import org.apache.ibatis.logging.LogFactory; 19 | 20 | /** 21 | * LoggerFactory is a wrapper around {@link LogFactory} to support {@link Logger}. 22 | * 23 | * @author Putthiphong Boonphong 24 | */ 25 | public class LoggerFactory { 26 | 27 | /** 28 | * Instantiates a new logger factory. 29 | */ 30 | private LoggerFactory() { 31 | // NOP 32 | } 33 | 34 | /** 35 | * Gets the logger. 36 | * 37 | * @param aClass 38 | * the a class 39 | * 40 | * @return the logger 41 | */ 42 | public static Logger getLogger(Class aClass) { 43 | return new Logger(LogFactory.getLog(aClass)); 44 | } 45 | 46 | /** 47 | * Gets the logger. 48 | * 49 | * @param logger 50 | * the logger 51 | * 52 | * @return the logger 53 | */ 54 | public static Logger getLogger(String logger) { 55 | return new Logger(LogFactory.getLog(logger)); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/annotation/factory/SimpleFactoryBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.annotation.factory; 17 | 18 | import org.springframework.beans.factory.FactoryBean; 19 | import org.springframework.beans.factory.annotation.Autowired; 20 | import org.springframework.context.ApplicationContext; 21 | import org.springframework.stereotype.Component; 22 | 23 | @Component 24 | public class SimpleFactoryBean implements FactoryBean { 25 | 26 | private static boolean isInitializedEarly = false; 27 | 28 | public SimpleFactoryBean() { 29 | isInitializedEarly = true; 30 | throw new RuntimeException(); 31 | } 32 | 33 | @Autowired 34 | public SimpleFactoryBean(ApplicationContext context) { 35 | if (isInitializedEarly) { 36 | throw new RuntimeException(); 37 | } 38 | } 39 | 40 | @Override 41 | public Object getObject() { 42 | return new Object(); 43 | } 44 | 45 | @Override 46 | public Class getObjectType() { 47 | return Object.class; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | MyBatis Spring 2 | Copyright 2010-2023 3 | 4 | This product includes software developed by 5 | The MyBatis Team (http://www.mybatis.org/). 6 | 7 | iBATIS 8 | This product includes software developed by 9 | The Apache Software Foundation (http://www.apache.org/). 10 | 11 | Copyright 2010 The Apache Software Foundation 12 | 13 | Licensed under the Apache License, Version 2.0 (the "License"); 14 | you may not use this file except in compliance with the License. 15 | You may obtain a copy of the License at 16 | 17 | http://www.apache.org/licenses/LICENSE-2.0 18 | 19 | Unless required by applicable law or agreed to in writing, software 20 | distributed under the License is distributed on an "AS IS" BASIS, 21 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | See the License for the specific language governing permissions and 23 | limitations under the License. 24 | 25 | Spring Framework 26 | All Spring projects are licensed under the terms of the Apache License, Version 2.0 27 | 28 | Copyright 2002-2010 the original author or authors 29 | 30 | Licensed under the Apache License, Version 2.0 (the "License"); 31 | you may not use this file except in compliance with the License. 32 | You may obtain a copy of the License at 33 | 34 | http://www.apache.org/licenses/LICENSE-2.0 35 | 36 | Unless required by applicable law or agreed to in writing, software 37 | distributed under the License is distributed on an "AS IS" BASIS, 38 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 39 | See the License for the specific language governing permissions and 40 | limitations under the License. 41 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/config/base-package.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 25 | 31 | 32 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/site/es/markdown/using-api.md: -------------------------------------------------------------------------------- 1 | 2 | # Using the MyBatis API 3 | 4 | With MyBatis-Spring, you can continue to directly use the MyBatis API. 5 | Simply create an `SqlSessionFactory` in Spring using `SqlSessionFactoryBean` and use the factory in your code. 6 | 7 | ```java 8 | public class UserDaoImpl implements UserDao { 9 | // SqlSessionFactory would normally be set by SqlSessionDaoSupport 10 | private final SqlSessionFactory sqlSessionFactory; 11 | 12 | public UserDaoImpl(SqlSessionFactory sqlSessionFactory) { 13 | this.sqlSessionFactory = sqlSessionFactory; 14 | } 15 | 16 | public User getUser(String userId) { 17 | // note standard MyBatis API usage - opening and closing the session manually 18 | try (SqlSession session = sqlSessionFactory.openSession()) { 19 | return session.selectOne("org.mybatis.spring.sample.mapper.UserMapper.getUser", userId); 20 | } 21 | } 22 | } 23 | ``` 24 | 25 | Use this option **with care** because wrong usage may produce runtime errors or worse, data integrity problems. Be aware of the following caveats with direct API usage: 26 | 27 | * It will **not** participate in any Spring transactions. 28 | * If the `SqlSession` is using a `DataSource` that is also being used by a Spring transaction manager and there is currently a transaction in progress, this code will throw an exception. 29 | * MyBatis' `DefaultSqlSession` is not thread safe. If you inject it in your beans you will get errors. 30 | * Mappers created using `DefaultSqlSession` are not thread safe either. If you inject them it in your beans you will get errors. 31 | * You must make sure that your `SqlSession`s are **always** closed in a finally block. 32 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/batch/domain/Employee.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.batch.domain; 17 | 18 | import java.util.List; 19 | 20 | public class Employee { 21 | 22 | private int id; 23 | private String name; 24 | private int salary; 25 | private List skills; 26 | 27 | public int getId() { 28 | return id; 29 | } 30 | 31 | public void setId(int id) { 32 | this.id = id; 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public void setName(String name) { 40 | this.name = name; 41 | } 42 | 43 | public int getSalary() { 44 | return salary; 45 | } 46 | 47 | public void setSalary(int salary) { 48 | this.salary = salary; 49 | } 50 | 51 | public List getSkills() { 52 | return skills; 53 | } 54 | 55 | public void setSkills(List skills) { 56 | this.skills = skills; 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return "Employee{" + "id=" + id + ", name='" + name + '\'' + ", salary=" + salary + ", skills=" + skills + '}'; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/sample/SampleSqlSessionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.sample; 17 | 18 | import static org.assertj.core.api.Assertions.assertThat; 19 | 20 | import org.junit.jupiter.api.Test; 21 | import org.mybatis.spring.sample.service.BarService; 22 | import org.springframework.beans.factory.annotation.Autowired; 23 | import org.springframework.test.annotation.DirtiesContext; 24 | import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; 25 | 26 | /** 27 | * Example of basic MyBatis-Spring integration usage with a manual DAO implementation that subclasses 28 | * SqlSessionDaoSupport. 29 | */ 30 | @DirtiesContext 31 | @SpringJUnitConfig(locations = { "classpath:org/mybatis/spring/sample/config/applicationContext-sqlsession.xml" }) 32 | class SampleSqlSessionTest { 33 | 34 | @Autowired 35 | private BarService barService; 36 | 37 | @Test 38 | void testFooService() { 39 | var user = this.barService.doSomeBusinessStuff("u1"); 40 | assertThat(user).isNotNull(); 41 | assertThat(user.getName()).isEqualTo("Pocoyo"); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/type/DummyTypeHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.type; 17 | 18 | import java.math.BigInteger; 19 | import java.sql.CallableStatement; 20 | import java.sql.PreparedStatement; 21 | import java.sql.ResultSet; 22 | import java.sql.SQLException; 23 | 24 | import org.apache.ibatis.type.JdbcType; 25 | import org.apache.ibatis.type.MappedTypes; 26 | import org.apache.ibatis.type.TypeHandler; 27 | 28 | @MappedTypes(BigInteger.class) 29 | public class DummyTypeHandler implements TypeHandler { 30 | 31 | @Override 32 | public void setParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType) throws SQLException { 33 | } 34 | 35 | @Override 36 | public Object getResult(ResultSet rs, String columnName) throws SQLException { 37 | return null; 38 | } 39 | 40 | @Override 41 | public Object getResult(CallableStatement cs, int columnIndex) throws SQLException { 42 | return null; 43 | } 44 | 45 | @Override 46 | public Object getResult(ResultSet rs, int columnIndex) throws SQLException { 47 | return null; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/type/DummyTypeHandler2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.type; 17 | 18 | import java.math.BigDecimal; 19 | import java.sql.CallableStatement; 20 | import java.sql.PreparedStatement; 21 | import java.sql.ResultSet; 22 | import java.sql.SQLException; 23 | 24 | import org.apache.ibatis.type.JdbcType; 25 | import org.apache.ibatis.type.MappedTypes; 26 | import org.apache.ibatis.type.TypeHandler; 27 | 28 | @MappedTypes(BigDecimal.class) 29 | public class DummyTypeHandler2 implements TypeHandler { 30 | 31 | @Override 32 | public void setParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType) throws SQLException { 33 | } 34 | 35 | @Override 36 | public Object getResult(ResultSet rs, String columnName) throws SQLException { 37 | return null; 38 | } 39 | 40 | @Override 41 | public Object getResult(CallableStatement cs, int columnIndex) throws SQLException { 42 | return null; 43 | } 44 | 45 | @Override 46 | public Object getResult(ResultSet rs, int columnIndex) throws SQLException { 47 | return null; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/config/factory-ref.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 25 | 31 | 32 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/config/template-ref.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 25 | 31 | 32 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/site/markdown/using-api.md: -------------------------------------------------------------------------------- 1 | 2 | # Using the MyBatis API 3 | 4 | With MyBatis-Spring, you can continue to directly use the MyBatis API. Simply create an `SqlSessionFactory` in Spring using `SqlSessionFactoryBean` and use the factory in your code. 5 | 6 | ```java 7 | public class UserDaoImpl implements UserDao { 8 | // SqlSessionFactory would normally be set by SqlSessionDaoSupport 9 | private final SqlSessionFactory sqlSessionFactory; 10 | 11 | public UserDaoImpl(SqlSessionFactory sqlSessionFactory) { 12 | this.sqlSessionFactory = sqlSessionFactory; 13 | } 14 | 15 | public User getUser(String userId) { 16 | // note standard MyBatis API usage - opening and closing the session manually 17 | try (SqlSession session = sqlSessionFactory.openSession()) { 18 | return session.selectOne("org.mybatis.spring.sample.mapper.UserMapper.getUser", userId); 19 | } 20 | } 21 | } 22 | ``` 23 | 24 | Use this option **with care** because wrong usage may produce runtime errors or worse, data integrity problems. Be aware of the following caveats with direct API usage: 25 | 26 | * Unless **explicitly managed by Spring's `@Transactional` annotation** or configured for **auto-commit** at the database connection level, the raw `SqlSession` does **not** participate in any transaction management. Reliance on the raw `SqlSession` is highly discouraged as it bypasses Spring's automatic resource management mechanism. 27 | * MyBatis' `DefaultSqlSession` is not thread safe. If you inject it in your beans you **will** get errors. 28 | * Mappers created using `DefaultSqlSession` are not thread safe either. If you inject them it in your beans you **will** get errors. 29 | * You must make sure that your `SqlSession`s are **always** closed in a finally block. -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/config/annotation.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 25 | 31 | 32 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/submitted/xa/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.submitted.xa; 17 | 18 | import org.springframework.beans.factory.annotation.Autowired; 19 | import org.springframework.stereotype.Service; 20 | import org.springframework.transaction.annotation.Transactional; 21 | 22 | @Service 23 | public class UserServiceImpl implements UserService { 24 | 25 | @Autowired 26 | private UserMapper userMapperMaster; 27 | @Autowired 28 | private UserMapper userMapperSlave; 29 | 30 | @Override 31 | @Transactional 32 | public void saveWithNoFailure(User user) { 33 | userMapperMaster.save(user); 34 | userMapperSlave.save(user); 35 | } 36 | 37 | @Override 38 | @Transactional 39 | public void saveWithFailure(User user) { 40 | userMapperMaster.save(user); 41 | userMapperSlave.save(user); 42 | throw new RuntimeException("failed!"); 43 | } 44 | 45 | @Override 46 | public boolean checkUserExists(int id) { 47 | if (userMapperMaster.select(id) != null || userMapperSlave.select(id) != null) { 48 | return true; 49 | } 50 | return false; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/spring/transaction/SpringManagedTransactionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.transaction; 17 | 18 | import java.sql.Connection; 19 | import java.util.Properties; 20 | 21 | import javax.sql.DataSource; 22 | 23 | import org.apache.ibatis.session.TransactionIsolationLevel; 24 | import org.apache.ibatis.transaction.Transaction; 25 | import org.apache.ibatis.transaction.TransactionFactory; 26 | 27 | /** 28 | * Creates a {@code SpringManagedTransaction}. 29 | * 30 | * @author Hunter Presnall 31 | */ 32 | public class SpringManagedTransactionFactory implements TransactionFactory { 33 | 34 | @Override 35 | public Transaction newTransaction(DataSource dataSource, TransactionIsolationLevel level, boolean autoCommit) { 36 | return new SpringManagedTransaction(dataSource); 37 | } 38 | 39 | @Override 40 | public Transaction newTransaction(Connection conn) { 41 | throw new UnsupportedOperationException("New Spring transactions require a DataSource"); 42 | } 43 | 44 | @Override 45 | public void setProperties(Properties props) { 46 | // not needed in this version 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/sample/SampleJavaConfigTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * MyBatis @Configuration style sample 18 | */ 19 | package org.mybatis.spring.sample; 20 | 21 | import static org.assertj.core.api.Assertions.assertThat; 22 | 23 | import org.junit.jupiter.api.Test; 24 | import org.mybatis.spring.sample.config.SampleConfig; 25 | import org.mybatis.spring.sample.service.FooService; 26 | import org.springframework.beans.factory.annotation.Autowired; 27 | import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; 28 | 29 | @SpringJUnitConfig(classes = SampleConfig.class) 30 | class SampleJavaConfigTest { 31 | 32 | @Autowired 33 | private FooService fooService; 34 | 35 | @Autowired 36 | private FooService fooServiceWithMapperFactoryBean; 37 | 38 | @Test 39 | void test() { 40 | var user = fooService.doSomeBusinessStuff("u1"); 41 | assertThat(user.getName()).isEqualTo("Pocoyo"); 42 | } 43 | 44 | @Test 45 | void testWithMapperFactoryBean() { 46 | var user = fooServiceWithMapperFactoryBean.doSomeBusinessStuff("u1"); 47 | assertThat(user.getName()).isEqualTo("Pocoyo"); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/config/marker-interface.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 25 | 31 | 32 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/sample/config/applicationContext-mapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 25 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/PooledMockDataSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring; 17 | 18 | import com.mockrunner.mock.jdbc.MockDataSource; 19 | 20 | import java.sql.Connection; 21 | import java.sql.SQLException; 22 | import java.util.LinkedList; 23 | 24 | final class PooledMockDataSource extends MockDataSource { 25 | 26 | private int connectionCount = 0; 27 | 28 | private LinkedList connections = new LinkedList<>(); 29 | 30 | @Override 31 | public Connection getConnection() throws SQLException { 32 | if (connections.isEmpty()) { 33 | throw new SQLException("Sorry, I ran out of connections"); 34 | } 35 | ++this.connectionCount; 36 | return this.connections.removeLast(); 37 | } 38 | 39 | int getConnectionCount() { 40 | return this.connectionCount; 41 | } 42 | 43 | void reset() { 44 | this.connectionCount = 0; 45 | this.connections.clear(); 46 | } 47 | 48 | @Override 49 | public void setupConnection(Connection connection) { 50 | throw new UnsupportedOperationException("used addConnection() instead"); 51 | } 52 | 53 | public void addConnection(Connection c) { 54 | this.connections.add(c); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/sample/config/applicationContext-scanner.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 24 | 28 | 29 | 30 | 31 | 32 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/spring/annotation/MapperScans.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2025 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.annotation; 17 | 18 | import java.lang.annotation.Documented; 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | import org.springframework.context.annotation.Import; 25 | 26 | /** 27 | * The Container annotation that aggregates several {@link MapperScan} annotations. 28 | *

29 | * Can be used natively, declaring several nested {@link MapperScan} annotations. Can also be used in conjunction with 30 | * Java 8's support for repeatable annotations, where {@link MapperScan} can simply be declared several times on the 31 | * same method, implicitly generating this container annotation. 32 | * 33 | * @author Kazuki Shimizu 34 | * 35 | * @since 2.0.0 36 | * 37 | * @see MapperScan 38 | */ 39 | @Retention(RetentionPolicy.RUNTIME) 40 | @Target(ElementType.TYPE) 41 | @Documented 42 | @Import(MapperScannerRegistrar.RepeatingRegistrar.class) 43 | public @interface MapperScans { 44 | 45 | /** 46 | * Value. 47 | * 48 | * @return the mapper scan[] 49 | */ 50 | MapperScan[] value(); 51 | } 52 | -------------------------------------------------------------------------------- /.mvn/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | 24 | 25 | central 26 | ${env.CI_DEPLOY_USERNAME} 27 | ${env.CI_DEPLOY_PASSWORD} 28 | 29 | 30 | 31 | 32 | gh-pages-scm 33 | 34 | branch 35 | gh-pages 36 | 37 | 38 | 39 | 40 | 41 | github 42 | ${env.GITHUB_TOKEN} 43 | 44 | 45 | 46 | 47 | nvd 48 | ${env.NVD_API_KEY} 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/config/marker-and-annotation.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 25 | 31 | 32 | 35 | 38 | 39 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/sample/config/applicationContext-batch.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 23 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/sample/config/applicationContext-namespace.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 24 | 30 | 31 | 32 | 33 | 34 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/core/jdk/type/AtomicNumberTypeHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.core.jdk.type; 17 | 18 | import java.sql.CallableStatement; 19 | import java.sql.PreparedStatement; 20 | import java.sql.ResultSet; 21 | import java.sql.SQLException; 22 | import java.util.concurrent.atomic.AtomicInteger; 23 | import java.util.concurrent.atomic.AtomicLong; 24 | 25 | import org.apache.ibatis.type.JdbcType; 26 | import org.apache.ibatis.type.MappedTypes; 27 | import org.apache.ibatis.type.TypeHandler; 28 | 29 | @MappedTypes({ AtomicInteger.class, AtomicLong.class }) 30 | public class AtomicNumberTypeHandler implements TypeHandler { 31 | 32 | public AtomicNumberTypeHandler(Class type) { 33 | } 34 | 35 | @Override 36 | public void setParameter(PreparedStatement ps, int i, Number parameter, JdbcType jdbcType) throws SQLException { 37 | } 38 | 39 | @Override 40 | public Number getResult(ResultSet rs, String columnName) throws SQLException { 41 | return null; 42 | } 43 | 44 | @Override 45 | public Number getResult(CallableStatement cs, int columnIndex) throws SQLException { 46 | return null; 47 | } 48 | 49 | @Override 50 | public Number getResult(ResultSet rs, int columnIndex) throws SQLException { 51 | return null; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/config/default-scope.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/sample/config/applicationContext-sqlsession.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 23 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | org.mybatis.spring.sample.mapper.UserMapper 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/config/process-property-placeholders-false.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/submitted/webapp_placeholder/spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/config/process-property-placeholders-true.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/spring/submitted/webapp_placeholder/WebappPlaceholderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.spring.submitted.webapp_placeholder; 17 | 18 | import static org.assertj.core.api.Assertions.assertThat; 19 | 20 | import org.apache.ibatis.session.SqlSessionFactory; 21 | import org.junit.jupiter.api.Assertions; 22 | import org.junit.jupiter.api.Test; 23 | import org.junit.jupiter.api.extension.ExtendWith; 24 | import org.springframework.beans.factory.annotation.Autowired; 25 | import org.springframework.context.ApplicationContext; 26 | import org.springframework.test.context.junit.jupiter.SpringExtension; 27 | import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; 28 | import org.springframework.test.context.web.WebAppConfiguration; 29 | 30 | @ExtendWith(SpringExtension.class) 31 | @WebAppConfiguration 32 | @SpringJUnitConfig(locations = "classpath:org/mybatis/spring/submitted/webapp_placeholder/spring.xml") 33 | class WebappPlaceholderTest { 34 | 35 | @Autowired 36 | private SqlSessionFactory sqlSessionFactory; 37 | 38 | @Autowired 39 | private ApplicationContext applicationContext; 40 | 41 | @Test 42 | void testName() { 43 | Assertions.assertEquals(0, sqlSessionFactory.getConfiguration().getMapperRegistry().getMappers().size()); 44 | var mapper = applicationContext.getBean(Mapper.class); 45 | assertThat(mapper).isNotNull(); 46 | Assertions.assertEquals(1, sqlSessionFactory.getConfiguration().getMapperRegistry().getMappers().size()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/site/zh_CN/markdown/sample.md: -------------------------------------------------------------------------------- 1 | 2 | # 示例代码 3 | 4 | 提示 5 | 查看 [JPetstore 6 demo](https://github.com/mybatis/jpetstore-6) 了解如何在完整的 Web 应用服务器上使用 Spring。 6 | 7 | 您可以在 MyBatis-Spring 的 [代码仓库](https://github.com/mybatis/spring/tree/master/src/test/java/org/mybatis/spring/sample) 中查看示例代码: 8 | 9 | 所有示例都能在 JUnit 5 下运行。 10 | 11 | 示例代码演示了事务服务从数据访问层获取域对象的典型设计。 12 | 13 | `FooService.java` 作为服务: 14 | 15 | ```java 16 | @Transactional 17 | public class FooService { 18 | 19 | private final UserMapper userMapper; 20 | 21 | public FooService(UserMapper userMapper) { 22 | this.userMapper = userMapper; 23 | } 24 | 25 | public User doSomeBusinessStuff(String userId) { 26 | return this.userMapper.getUser(userId); 27 | } 28 | 29 | } 30 | ``` 31 | 32 | 它是一个事务 bean,所以当调用它的任何方法时,事务被启动,在方法结束且没有抛出任何未经检查的异常的时候事务将会被提交。注意,事务的行为可以通过 `@Transactional` 的属性进行配置。这不是必需的;你可以使用 Spring 提供的任何其他方式来划分你的事务范围。 33 | 34 | 此服务调用使用 MyBatis 构建的数据访问层.。该层只包含一个接口,`UserMapper.java`,这将被 MyBatis 构建的动态代理使用,在运行时通过 Spring 注入到服务之中。 35 | 36 | ```java 37 | public interface UserMapper { 38 | 39 | User getUser(String userId); 40 | 41 | } 42 | ``` 43 | 44 | 注意,为了简单起见,我们使用了接口 `UserMapper.java`。在使用 DAO 的场景中,一个 DAO 类应该分为一个接口和一个实现类。回到这个例子里,准确来说,这个接口应该叫 `UserDao.java` 。 45 | 46 | 我们将看到不同的方法来发现映射器接口,将其注册到 Spring 并将其注入到服务 bean 中: 47 | 48 | ## 测试场景 49 | 50 | | 样例测试 | 描述 | 51 | | --- | --- | 52 | | `SampleMapperTest.java` | 演示基于 `MapperFactoryBean` 的基本配置,这将动态构建 `UserMapper` 的一个实现。 | 53 | | `SampleScannerTest.java` | 演示如何使用 `MapperScannerConfigurer` 来自动发现项目中所有的映射器。 | 54 | | `SampleSqlSessionTest.java` | 演示如何基于 Spring 管理的 `SqlSession` 手动编写 DAO,并在 `UserDaoImpl.java` 中提供你自己的实现。 | 55 | | `SampleEnableTest.java` | 演示如何使用 Spring 的 `@Configuration` 和 `@MapperScann` 注解来自动发现 mappers. | 56 | | `SampleNamespaceTest.java` | 演示如何使用自定义 MyBatis XML 命名空间. | 57 | | `SampleJavaConfigTest.java` | 演示如何基于 Spring 的 `@Configuration` 来手工创建 MyBatis 的 bean。 | 58 | | `SampleJobJavaConfigTest.java` | 演示如何在 Java 配置中使用 Spring Batch 中的 `ItemReader` 和 `ItemWriter`。 | 59 | | `SampleJobXmlConfigTest.java` | 演示如何在 XML 配置中使用 Spring Batch 中的 `ItemReader` 和 `ItemWriter`。 | 60 | 61 | 查看不同的 `applicationContext.xml` 文件以了解 MyBatis-Spring 在实践中是如何运用的。 62 | 63 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/filter/xml/appContextAspectJFilter.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 22 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/filter/xml/appContextCustFilter.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 22 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/spring/filter/xml/appContextInvalidFilter1.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 22 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 43 | 44 | 45 | 46 | --------------------------------------------------------------------------------