{"id":19243485,"url":"https://github.com/bootique/bootique-mybatis","last_synced_at":"2025-04-21T09:33:12.054Z","repository":{"id":52611378,"uuid":"235580207","full_name":"bootique/bootique-mybatis","owner":"bootique","description":"Provides LinkMove integration with Bootique","archived":false,"fork":false,"pushed_at":"2025-04-19T13:22:53.000Z","size":97,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-19T18:03:30.476Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://bootique.io","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bootique.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-01-22T13:33:41.000Z","updated_at":"2025-04-19T13:22:56.000Z","dependencies_parsed_at":"2023-11-24T21:21:54.695Z","dependency_job_id":"b21ca6e9-6842-423f-82e5-a9fc22e3e272","html_url":"https://github.com/bootique/bootique-mybatis","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bootique%2Fbootique-mybatis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bootique%2Fbootique-mybatis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bootique%2Fbootique-mybatis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bootique%2Fbootique-mybatis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bootique","download_url":"https://codeload.github.com/bootique/bootique-mybatis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250032355,"owners_count":21363824,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T17:18:12.760Z","updated_at":"2025-04-21T09:33:07.034Z","avatar_url":"https://github.com/bootique.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!--\n  Licensed to ObjectStyle LLC under one\n  or more contributor license agreements.  See the NOTICE file\n  distributed with this work for additional information\n  regarding copyright ownership.  The ObjectStyle LLC licenses\n  this file to you under the Apache License, Version 2.0 (the\n  \"License\"); you may not use this file except in compliance\n  with the License.  You may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\n  Unless required by applicable law or agreed to in writing,\n  software distributed under the License is distributed on an\n  \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n  KIND, either express or implied.  See the License for the\n  specific language governing permissions and limitations\n  under the License.\n  --\u003e\n\n[![build test deploy](https://github.com/bootique/bootique-mybatis/actions/workflows/maven.yml/badge.svg)](https://github.com/bootique/bootique-mybatis/actions/workflows/maven.yml)\n[![Maven Central](https://img.shields.io/maven-central/v/io.bootique.mybatis/bootique-mybatis.svg?colorB=brightgreen)](https://search.maven.org/artifact/io.bootique.mybatis/bootique-mybatis/)\n\n# bootique-mybatis\n\nProvides [MyBatis](https://mybatis.org/mybatis-3/) integration with [Bootique](https://bootique.io).\n\n*For additional help/questions about this example send a message to\n[Bootique forum](https://groups.google.com/forum/#!forum/bootique-user).*\n\n# Setup\n\n## Add `bootique-mybatis` to your build\n\nAdd the dependency on `bootique-mybatis` to your build. Here is a Maven example:\n```xml\n\u003cdependencyManagement\u003e\n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003eio.bootique.bom\u003c/groupId\u003e\n            \u003cartifactId\u003ebootique-bom\u003c/artifactId\u003e\n            \u003cversion\u003eX.X\u003c/version\u003e\n            \u003ctype\u003epom\u003c/type\u003e\n            \u003cscope\u003eimport\u003c/scope\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n\u003c/dependencyManagement\u003e\n...\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.bootique.mybatis\u003c/groupId\u003e\n    \u003cartifactId\u003ebootique-mybatis\u003c/artifactId\u003e\n\u003c/dependency\u003e\n```\nAfter that you can configure a number of things (mappers, type handlers) in the code and use Bootique-provided DataSource, and/or use MyBatis XML configuration. Below are a the examples of both.\n\n## Configure Extensions in the Code / DataSource Provided by Bootique\n\nConfigure MyBatis mappers and type handlers in the code:\n```java\npublic class MyModule implements Module {\n\n\tpublic void configure(Binder binder) {\n\n\t\t// add annotated Mappers ...\n\t\tMybatisModule.extend(binder)\n\t\t\t// ... a whole package of Mappers\n\t\t\t.addMapperPackage(MyMapper1.class.getPackage())\n\t\t\t// ... a single mapper\n\t\t\t.addMapper(MyMapper2.class)\n\t\t\t// ... a whole package of TypeHandlers\n\t\t\t.addTypeHandlerPackage(MyTH1.class.getPackage())\n\t\t\t// ... a single mapper\n\t\t\t.addTypeHandler(MyTH.class))\n    }\n}\n```\n\nConfigure DataSource in Bootique:\n\n```yaml\n# Implicit single DataSource. MyBatis will find and use it automatically.\njdbc:\n  myds:\n    jdbcUrl: \"jdbc:mysql://127.0.0.1:3306/mydb\"\n    username: root\n    password: secret\n```\n\n```yaml\njdbc:\n  myds:\n    jdbcUrl: \"jdbc:mysql://127.0.0.1/mydb\"\n    username: root\n    password: secret\n\n# Explicitly reference a named DataSource\nmybatis:\n  datasource: myds\n```\n\n## Configure Anything in MyBatis XML\n\nIf you'd rather prefer to use MyBatis \"canonical\" approach with an XML config file, you can still do that (optionally\ncombining it with Bootique-configured DataSource).\n\nFirst, configure a reference to MyBatis XML:\n```yaml\nmybatis:\n  environmentId: qa\n  config: classpath:mybatis-config.xml\n```\nSecond create MyBatis config XML as you normally would. In this example it contains the `\u003cenvironment\u003e..\u003c/environment\u003e`\nsection with DB connection info. If you omit the \"environment\" config, make sure you configure a Bootique\nDataSource in YAML as described above.\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\" ?\u003e\n\u003c!DOCTYPE configuration\n        PUBLIC \"-//mybatis.org//DTD Config 3.0//EN\"\n        \"http://mybatis.org/dtd/mybatis-3-config.dtd\"\u003e\n\u003cconfiguration\u003e\n    \u003cenvironments default=\"default\"\u003e\n\n        \u003c!-- If \"environment\" is not provided, Bootique will look for DataSource configuration in YAML --\u003e\n        \u003cenvironment id=\"qa\"\u003e\n            \u003ctransactionManager type=\"JDBC\"/\u003e\n            \u003cdataSource type=\"POOLED\"\u003e\n                \u003cproperty name=\"driver\" value=\"com.mysql.jdbc.Driver\"/\u003e\n                \u003cproperty name=\"url\" value=\"jdbc:mysql://127.0.0.1/mydb\"/\u003e\n                \u003cproperty name=\"username\" value=\"root\"/\u003e\n                \u003cproperty name=\"password\" value=\"secret\"/\u003e\n            \u003c/dataSource\u003e\n        \u003c/environment\u003e\n    \u003c/environments\u003e\n    \u003cmappers\u003e\n        \u003cmapper resource=\"com/foo/MyMapper1.xml\"/\u003e\n        \u003cmapper resource=\"com/foo/MyMapper2.xml\"/\u003e\n    \u003c/mappers\u003e\n\u003c/configuration\u003e\n```\n\n## Use MyBatis\n\nRegardless of how MyBatis was configured, you can use it in the same way, by injecting `SqlSessionManager`:\n\n```java\npublic class MyClass {\n\n\t@Inject\n\tprivate SqlSessionManager sessionManager;\n\n\tpublic void doSomething() {\n\t\ttry (SqlSession session = sessionManager.openSession()) {\n\t\t\tMyMapper2 mapper = session.getMapper(MyMapper2.class);\n\t\t\tOptional\u003cO1\u003e o1 = mapper.find(1);\n\t\t}\n\t}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbootique%2Fbootique-mybatis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbootique%2Fbootique-mybatis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbootique%2Fbootique-mybatis/lists"}