The project that the MyBatis integration with Spring Native feature.
- Java 11+
- GraalVM
- Spring Boot 2.6.3+
- Spring Native 0.11.2+
- MyBatis Spring 2.0.7+
- MyBatis Spring Boot 2.2.2+
Specify the mybatis-spring-native-core
on pom.xml
as follows:
Maven:
<dependencies>
<dependency>
<groupId>org.mybatis.spring.native</groupId>
<artifactId>mybatis-spring-native-core</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
</dependencies>
Gradle:
dependencies {
compile("org.mybatis.spring.native:mybatis-spring-native-core:0.1.0-SNAPSHOT")
}
If you use other extension modules provided by mybatis, please specify the mybatis-spring-native-extensions
instead of mybatis-spring-native-core
.
Maven:
<dependencies>
<dependency>
<groupId>org.mybatis.spring.native</groupId>
<artifactId>mybatis-spring-native-extensions</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
</dependencies>
Gradle:
dependencies {
compile("org.mybatis.spring.native:mybatis-spring-native-extensions:0.1.0-SNAPSHOT")
}
Add Sonatype OSS snapshot repository when use MyBatis's snapshot modules.
Maven:
<repositories>
<repository>
<id>sonatype-oss-snapshots</id>
<name>Sonatype OSS Snapshots Repository</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
Gradle:
repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
If you want to build this project, please will execute following procedures.
NOTE: Pre Conditions
Need to following environment variables are defined.
JAVA_HOME
GRAALVM_HOME
./mvnw -Pnative clean package
WARNING:
Building all modules takes long time.
./mvnw -pl core,samples/simple -Pnative clean package
NOTE:
Please replace the 'simple' part on above example to sample's suffix value(e.g. xml, sqlprovider and more) that you want to build.
./mvnw -pl core,extensions,samples/thymeleaf -Pnative clean package
Execute the following command when the build is completed.
./samples/simple/target/mybatis-spring-native-sample-simple
2022-01-22 13:45:10.453 INFO 2265 --- [ main] o.s.nativex.NativeListener : AOT mode enabled
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.6.3)
2022-01-22 13:45:10.455 INFO 2265 --- [ main] s.s.MybatisSpringNativeSampleApplication : Starting MybatisSpringNativeSampleApplication v0.1.0-SNAPSHOT using Java 17.0.1 on fv-az136-971 with PID 2265 (/home/runner/work/mybatis-spring-native/mybatis-spring-native/samples/simple/target/mybatis-spring-native-sample-simple started by runner in /home/runner/work/mybatis-spring-native/mybatis-spring-native)
2022-01-22 13:45:10.455 INFO 2265 --- [ main] s.s.MybatisSpringNativeSampleApplication : No active profile set, falling back to default profiles: default
2022-01-22 13:45:10.487 INFO 2265 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-01-22 13:45:10.491 INFO 2265 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-01-22 13:45:10.496 INFO 2265 --- [ main] s.s.MybatisSpringNativeSampleApplication : Started MybatisSpringNativeSampleApplication in 0.054 seconds (JVM running for 0.056)
2022-01-22 13:45:10.497 INFO 2265 --- [ main] s.s.MybatisSpringNativeSampleApplication : New city: City{id=4, name='NYC', state='NY', country='USA'}
2022-01-22 13:45:10.497 INFO 2265 --- [ main] s.s.MybatisSpringNativeSampleApplication : City{id=1, name='San Francisco', state='CA', country='USA'}
2022-01-22 13:45:10.497 INFO 2265 --- [ main] s.s.MybatisSpringNativeSampleApplication : City{id=2, name='Boston', state='MA', country='USA'}
2022-01-22 13:45:10.497 INFO 2265 --- [ main] s.s.MybatisSpringNativeSampleApplication : City{id=3, name='Portland', state='OR', country='USA'}
2022-01-22 13:45:10.497 INFO 2265 --- [ main] s.s.MybatisSpringNativeSampleApplication : City{id=4, name='NYC', state='NY', country='USA'}
2022-01-22 13:45:10.498 INFO 2265 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2022-01-22 13:45:10.499 INFO 2265 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
./samples/simple/target/mybatis-spring-native-sample-simple-exec.jar
2022-01-22 13:45:14.191 INFO 2305 --- [ main] o.s.nativex.NativeListener : AOT mode disabled
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.6.3)
2022-01-22 13:45:14.295 INFO 2305 --- [ main] s.s.MybatisSpringNativeSampleApplication : Starting MybatisSpringNativeSampleApplication v0.1.0-SNAPSHOT using Java 17.0.1 on fv-az136-971 with PID 2305 (/home/runner/work/mybatis-spring-native/mybatis-spring-native/samples/simple/target/mybatis-spring-native-sample-simple-0.1.0-SNAPSHOT-exec.jar started by runner in /home/runner/work/mybatis-spring-native/mybatis-spring-native)
2022-01-22 13:45:14.296 INFO 2305 --- [ main] s.s.MybatisSpringNativeSampleApplication : No active profile set, falling back to default profiles: default
2022-01-22 13:45:15.349 INFO 2305 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-01-22 13:45:15.578 INFO 2305 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-01-22 13:45:15.718 INFO 2305 --- [ main] s.s.MybatisSpringNativeSampleApplication : Started MybatisSpringNativeSampleApplication in 1.892 seconds (JVM running for 2.406)
2022-01-22 13:45:15.774 INFO 2305 --- [ main] s.s.MybatisSpringNativeSampleApplication : New city: City{id=4, name='NYC', state='NY', country='USA'}
2022-01-22 13:45:15.804 INFO 2305 --- [ main] s.s.MybatisSpringNativeSampleApplication : City{id=1, name='San Francisco', state='CA', country='USA'}
2022-01-22 13:45:15.805 INFO 2305 --- [ main] s.s.MybatisSpringNativeSampleApplication : City{id=2, name='Boston', state='MA', country='USA'}
2022-01-22 13:45:15.805 INFO 2305 --- [ main] s.s.MybatisSpringNativeSampleApplication : City{id=3, name='Portland', state='OR', country='USA'}
2022-01-22 13:45:15.806 INFO 2305 --- [ main] s.s.MybatisSpringNativeSampleApplication : City{id=4, name='NYC', state='NY', country='USA'}
2022-01-22 13:45:15.816 INFO 2305 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2022-01-22 13:45:15.823 INFO 2305 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
- https://spring.io/blog/2021/12/29/go-go-graalvm-with-spring-native-my-adventures-in-native-image-ville
- https://joshlong.com/jl/blogPost/mybatis-and-spring-native.html
- spring-attic/spring-native#404
- https://www.youtube.com/watch?v=EWWq3ts9Tv4&t=1s
Thanks for helping this project creation!!
-
Josh Long(@joshlong)
Josh provided the first sample application. -
Stéphane Nicoll(@snicoll)
Stéphane resolved and helped some issues for running MyBatis on native image.