Skip to content

SQL template file not found in case the application is embedded in spring boot jar file #55

Closed
@ruimo

Description

@ruimo

When I run MyBatis with Spring Boot, it fails to load SQL template file. It only occurs when I package application in a jar file (gradle bootJar).
When I trace the application with debugger, it fails the SQL template file existence check (the exists() method Line 207 of TemplateFilePathProvider class). The code checks if the file actually exists. However, the SQL template file is in Jar file, so the check fails.

http://mybatis.org/freemarker-scripting/jacoco/org.mybatis.scripting.freemarker.support/TemplateFilePathProvider.java.html

MyBatis version

3.5.4
OpenJDK 1.8.0_202
SpringBoot 2.2.6
Ubuntu 18.04

Database vendor and version

h2 1.4.200

Test case or example project

https://github.com/ruimo/sqlfilenotfound

Steps to reproduce

$./gradlew bootJar

$java -jar build/libs/TEST_Service-1.0-SNAPSHOT.jar

Expected result

$ curl http://localhost:8888/api/customers
[]

Actual result

$ curl http://localhost:8888/api/customers
{"timestamp":"2020-05-26T11:43:13.936+0000","status":500,"error":"Internal Server Error","message":"nested exception is org.apache.ibatis.builder.BuilderException: Error invoking SqlProvider method 'public static java.lang.String org.mybatis.scripting.thymeleaf.support.TemplateFilePathProvider.provideSql(org.apache.ibatis.builder.annotation.ProviderContext)' with specify parameter 'null'. Cause: java.lang.IllegalStateException: The SQL template file not found. mapperType:[interface com.example.domainparts.sample.customer.db.CustomerMapper] mapperMethod:[public abstract java.util.List com.example.domainparts.sample.customer.db.CustomerMapper.list()] databaseId:[null]","path":"/api/customers"}

Note

The bootRun become an expected result.

$./gradlew bootRun
$ curl http://localhost:8888/api/customers
[]

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions