Skip to content

Commit

Permalink
✨ Support Mapper XML based on MyBatis for Spring Boot 3 Native
Browse files Browse the repository at this point in the history
  • Loading branch information
xuxiaowei-com-cn committed Aug 8, 2024
1 parent c00ce4f commit d624c02
Show file tree
Hide file tree
Showing 29 changed files with 1,338 additions and 4 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/native.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ jobs:
# run: xcode-select --install

- name: Test with Spring Boot Native Latest
run: ./mvnw -V compile -Pnative native:compile -am -pl mybatis-spring-boot-samples/mybatis-spring-boot-sample-graalvm-annotation
run: ./mvnw -V compile -Pnative native:compile -am -pl mybatis-spring-boot-samples/mybatis-spring-boot-sample-graalvm-annotation,mybatis-spring-boot-samples/mybatis-spring-boot-sample-graalvm-xml

- name: Run Native Latest
run: mybatis-spring-boot-samples/mybatis-spring-boot-sample-graalvm-annotation/target/mybatis-spring-boot-sample-graalvm-annotation
run: |
mybatis-spring-boot-samples/mybatis-spring-boot-sample-graalvm-annotation/target/mybatis-spring-boot-sample-graalvm-annotation
mybatis-spring-boot-samples/mybatis-spring-boot-sample-graalvm-xml/target/mybatis-spring-boot-sample-graalvm-xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
{ "name": "java.util.ArrayList", "methods": [{ "name": "<init>", "parameterTypes": [] }] },
{ "name": "java.util.HashMap", "methods": [{ "name": "<init>", "parameterTypes": [] }] },
{ "name": "java.util.TreeSet", "methods": [{ "name": "<init>", "parameterTypes": [] }] },
{ "name": "java.util.HashSet", "methods": [{ "name": "<init>", "parameterTypes": [] }] }
{ "name": "java.util.HashSet", "methods": [{ "name": "<init>", "parameterTypes": [] }] },
{ "name": "org.apache.ibatis.session.Configuration", "methods": [{ "name": "<init>", "parameterTypes": [] }] },
{ "name": "org.mybatis.spring.boot.autoconfigure.SpringBootVFS", "methods": [{ "name": "<init>", "parameterTypes": [] }] }
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"resources": {
"includes": [
{ "pattern": "org/apache/ibatis/builder/xml/mybatis-3-config.dtd" },
{ "pattern": "org/apache/ibatis/builder/xml/mybatis-3-mapper.dtd" },
{ "pattern": "org/apache/ibatis/builder/xml/mybatis-config.xsd" },
{ "pattern": "org/apache/ibatis/builder/xml/mybatis-mapper.xsd" }
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
# limitations under the License.
#

Args = -H:ReflectionConfigurationResources=${.}/mybatis-reflection.json
Args = -H:ReflectionConfigurationResources=${.}/mybatis-reflection.json -H:ResourceConfigurationResources=${.}/mybatis-resource.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright ${license.git.copyrightYears} the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2015-2024 the original author or authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE Format>
<Format>
<!-- Dummy format file -->
</Format>
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2015-2024 the original author or authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-samples</artifactId>
<version>3.0.4-SNAPSHOT</version>
</parent>
<artifactId>mybatis-spring-boot-sample-graalvm-xml</artifactId>
<packaging>jar</packaging>
<name>mybatis-spring-boot-sample-graalvm-xml</name>
<properties>
<module.name>org.mybatis.spring.boot.sample.graalvmxml</module.name>
</properties>
<dependencies>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Spring-Boot-Native-Processed>true</Spring-Boot-Native-Processed>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<builder>paketobuildpacks/builder-jammy-tiny:latest</builder>
<env>
<BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
</env>
</image>
</configuration>
<executions>
<execution>
<id>process-aot</id>
<goals>
<goal>process-aot</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>${native-build-tools-plugin.version}</version>
<configuration>
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
<requiredVersion>22.3</requiredVersion>
</configuration>
<executions>
<execution>
<id>add-reachability-metadata</id>
<goals>
<goal>add-reachability-metadata</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
<profile>
<id>nativeTest</id>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>process-test-aot</id>
<goals>
<goal>process-test-aot</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>${native-build-tools-plugin.version}</version>
<configuration>
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
<requiredVersion>22.3</requiredVersion>
</configuration>
<executions>
<execution>
<id>native-test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2015-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sample.mybatis.graalvm.xml;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import sample.mybatis.graalvm.xml.dao.CityDao;
import sample.mybatis.graalvm.xml.mapper.CityMapper;
import sample.mybatis.graalvm.xml.mapper.HotelMapper;

@SpringBootApplication
public class SampleXmlApplication implements CommandLineRunner {

public static void main(String[] args) {
SpringApplication.run(SampleXmlApplication.class, args);
}

private final CityDao cityDao;

private final CityMapper cityMapper;

private final HotelMapper hotelMapper;

public SampleXmlApplication(CityDao cityDao, CityMapper cityMapper, HotelMapper hotelMapper) {
this.cityDao = cityDao;
this.cityMapper = cityMapper;
this.hotelMapper = hotelMapper;
}

@Override
@SuppressWarnings("squid:S106")
public void run(String... args) {
System.out.println(this.cityDao.selectCityById(1));
System.out.println(this.cityMapper.findByState("CA"));
System.out.println(this.cityMapper.listByState("ShanDong"));
System.out.println(this.cityMapper.mapByState("CA"));
System.out.println(this.cityMapper.listMapByState("ShanDong"));
System.out.println(this.cityMapper.treeSetStateByState("CN"));
System.out.println(this.cityMapper.hashSetStateByState("CN"));
System.out.println(this.hotelMapper.selectByCityId(1));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2015-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sample.mybatis.graalvm.xml.dao;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Component;

import sample.mybatis.graalvm.xml.domain.City;

/**
* @author Eddú Meléndez
*/
@Component
public class CityDao {

private final SqlSession sqlSession;

public CityDao(SqlSession sqlSession) {
this.sqlSession = sqlSession;
}

public City selectCityById(long id) {
return this.sqlSession.selectOne("selectCityById", id);
}

}
Loading

0 comments on commit d624c02

Please sign in to comment.