Integrate Spanner with MyBatis and Spring Boot (PostgreSQL)
Stay organized with collections
Save and categorize content based on your preferences.
MyBatis is a persistence framework with support for custom SQL
and advanced mappings. MyBatis eliminates most of the JDBC code
and manual setting of parameters and retrieval of results in your application.
Set up MyBatis for Spanner PostgreSQL-dialect databases
You can integrate Spanner PostgreSQL-dialect databases with MyBatis
and Spring Boot using the Spanner JDBC driver.
You don't need to use PGAdapter for this integration.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-03 UTC."],[],[],null,["# Integrate Spanner with MyBatis and Spring Boot (PostgreSQL)\n\n[MyBatis](https://mybatis.org/mybatis-3/) is a persistence framework with support for custom SQL\nand advanced mappings. MyBatis eliminates most of the JDBC code\nand manual setting of parameters and retrieval of results in your application.\n\nSet up MyBatis for Spanner PostgreSQL-dialect databases\n-------------------------------------------------------\n\nYou can integrate Spanner PostgreSQL-dialect databases with MyBatis\nand Spring Boot using the Spanner JDBC driver.\n\nYou don't need to use [PGAdapter](/spanner/docs/pgadapter) for this integration.\n\n### Dependencies\n\nIn your project, add Apache Maven dependencies for\n[MyBatis](https://mybatis.org/mybatis-3/), [Spring Boot](https://spring.io/projects/spring-boot), and the\n[Spanner JDBC driver](https://github.com/googleapis/java-spanner-jdbc). \n\n \u003cdependencies\u003e\n \u003c!-- MyBatis and Spring Boot --\u003e\n \u003cdependency\u003e\n \u003cgroupId\u003eorg.mybatis.spring.boot\u003c/groupId\u003e\n \u003cartifactId\u003emybatis-spring-boot-starter\u003c/artifactId\u003e\n \u003c/dependency\u003e\n \u003cdependency\u003e\n \u003cgroupId\u003eorg.mybatis.dynamic-sql\u003c/groupId\u003e\n \u003cartifactId\u003emybatis-dynamic-sql\u003c/artifactId\u003e\n \u003c/dependency\u003e\n\n \u003c!-- Spanner JDBC driver --\u003e\n \u003cdependency\u003e\n \u003cgroupId\u003ecom.google.cloud\u003c/groupId\u003e\n \u003cartifactId\u003egoogle-cloud-spanner-jdbc\u003c/artifactId\u003e\n \u003c/dependency\u003e\n \u003cdependencies\u003e\n\n### Data source configuration\n\nConfigure `application.properties` to use the Spanner JDBC driver and\nto connect to a Spanner PostgreSQL-dialect database. \n\n # This profile uses a Spanner PostgreSQL database.\n\n spanner.project=my-project\n spanner.instance=my-instance\n spanner.database=mybatis-sample\n\n spring.datasource.driver-class-name=com.google.cloud.spanner.jdbc.JdbcDriver\n spring.datasource.url=jdbc:cloudspanner:/projects/${spanner.project}/instances/${spanner.instance}/databases/${spanner.database}\n\nFull sample application\n-----------------------\n\nTo try this integration with a sample application, see\n[Spring Data MyBatis Sample Application with\nSpanner PostgreSQL](https://github.com/googleapis/java-spanner-jdbc/tree/main/samples/spring-data-mybatis/postgresql).\n\nWhat's next\n-----------\n\n- Learn more about [MyBatis](https://mybatis.org/mybatis-3/).\n- Learn more about [MyBatis and Spring Boot](https://mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure/index.html).\n- Learn more about [Spring Boot](https://spring.io/projects/spring-boot).\n- [File a GitHub issue](https://github.com/googleapis/java-spanner-jdbc/issues) to report a bug or ask a question about the Spanner JDBC driver."]]