diff --git a/mybatis-spring-boot-autoconfigure/src/main/java/org/mybatis/spring/boot/autoconfigure/MyBatisBeanFactoryInitializationAotProcessor.java b/mybatis-spring-boot-autoconfigure/src/main/java/org/mybatis/spring/boot/autoconfigure/MyBatisBeanFactoryInitializationAotProcessor.java index 4ec291d0a..74d241c62 100644 --- a/mybatis-spring-boot-autoconfigure/src/main/java/org/mybatis/spring/boot/autoconfigure/MyBatisBeanFactoryInitializationAotProcessor.java +++ b/mybatis-spring-boot-autoconfigure/src/main/java/org/mybatis/spring/boot/autoconfigure/MyBatisBeanFactoryInitializationAotProcessor.java @@ -58,6 +58,8 @@ class MyBatisBeanFactoryInitializationAotProcessor private static final String CONFIG_LOCATION = MybatisProperties.MYBATIS_PREFIX + ".config-location"; + private static final String MAPPER_LOCATIONS = MybatisProperties.MYBATIS_PREFIX + ".mapper-locations"; + private static final Set> EXCLUDE_CLASSES = new HashSet<>(); static { @@ -75,6 +77,7 @@ public BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableL Environment environment = beanFactory.getBean(Environment.class); configLocation(environment, hints); + mapperLocations(environment, hints); for (String beanName : beanNames) { BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName.substring(1)); @@ -101,14 +104,23 @@ private void configLocation(Environment environment, RuntimeHints hints) { if (StringUtils.hasText(configLocation)) { Resource resource = RESOURCE_RESOLVER.getResource(configLocation); if (resource.exists()) { - Stream.of(configLocation.replace(ResourceUtils.CLASSPATH_URL_PREFIX, "")) - .forEach(hints.resources()::registerPattern); + Stream.of(resource).forEach(hints.resources()::registerResource); } else { logger.error("{}: {} does not exist", CONFIG_LOCATION, configLocation); } } } + private void mapperLocations(Environment environment, RuntimeHints hints) { + String[] mapperLocations = environment.getProperty(MAPPER_LOCATIONS, String[].class); + if (mapperLocations != null) { + for (String mapperLocation : mapperLocations) { + Stream.of(mapperLocation.replace(ResourceUtils.CLASSPATH_URL_PREFIX, "")) + .forEach(hints.resources()::registerPattern); + } + } + } + private void registerMapperRelationships(Class mapperInterfaceType, RuntimeHints hints) { Method[] methods = ReflectionUtils.getAllDeclaredMethods(mapperInterfaceType); for (Method method : methods) { diff --git a/mybatis-spring-boot-samples/mybatis-spring-boot-sample-graalvm-xml/src/main/resources/META-INF/native-image/resource-config.json b/mybatis-spring-boot-samples/mybatis-spring-boot-sample-graalvm-xml/src/main/resources/META-INF/native-image/resource-config.json index d50272297..0f33d9bbc 100644 --- a/mybatis-spring-boot-samples/mybatis-spring-boot-sample-graalvm-xml/src/main/resources/META-INF/native-image/resource-config.json +++ b/mybatis-spring-boot-samples/mybatis-spring-boot-sample-graalvm-xml/src/main/resources/META-INF/native-image/resource-config.json @@ -1,8 +1,7 @@ { "resources": { "includes": [ - { "pattern": "sample/mybatis/graalvm/xml/mapper/CityMapper.xml" }, - { "pattern": "sample/mybatis/graalvm/xml/mapper/HotelMapper.xml" } + { "pattern": "sample/mybatis/graalvm/xml/mapper/CityMapper.xml" } ] } } diff --git a/mybatis-spring-boot-samples/mybatis-spring-boot-sample-graalvm-xml/src/main/resources/application.properties b/mybatis-spring-boot-samples/mybatis-spring-boot-sample-graalvm-xml/src/main/resources/application.properties index 3673a4708..e660f5f33 100644 --- a/mybatis-spring-boot-samples/mybatis-spring-boot-sample-graalvm-xml/src/main/resources/application.properties +++ b/mybatis-spring-boot-samples/mybatis-spring-boot-sample-graalvm-xml/src/main/resources/application.properties @@ -15,5 +15,6 @@ # mybatis.config-location=classpath:mybatis-config.xml +mybatis.mapper-locations=classpath:sample/mybatis/graalvm/xml/custommapper/*.xml logging.level.root=WARN logging.level.sample.mybatis.graalvm.xml.mapper=TRACE diff --git a/mybatis-spring-boot-samples/mybatis-spring-boot-sample-graalvm-xml/src/main/resources/mybatis-config.xml b/mybatis-spring-boot-samples/mybatis-spring-boot-sample-graalvm-xml/src/main/resources/mybatis-config.xml index 482f70862..cceaf408b 100644 --- a/mybatis-spring-boot-samples/mybatis-spring-boot-sample-graalvm-xml/src/main/resources/mybatis-config.xml +++ b/mybatis-spring-boot-samples/mybatis-spring-boot-sample-graalvm-xml/src/main/resources/mybatis-config.xml @@ -25,6 +25,5 @@ - diff --git a/mybatis-spring-boot-samples/mybatis-spring-boot-sample-graalvm-xml/src/main/resources/sample/mybatis/graalvm/xml/mapper/HotelMapper.xml b/mybatis-spring-boot-samples/mybatis-spring-boot-sample-graalvm-xml/src/main/resources/sample/mybatis/graalvm/xml/custommapper/HotelMapper.xml similarity index 100% rename from mybatis-spring-boot-samples/mybatis-spring-boot-sample-graalvm-xml/src/main/resources/sample/mybatis/graalvm/xml/mapper/HotelMapper.xml rename to mybatis-spring-boot-samples/mybatis-spring-boot-sample-graalvm-xml/src/main/resources/sample/mybatis/graalvm/xml/custommapper/HotelMapper.xml