Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ruimo opened this issue May 26, 2020 · 3 comments · Fixed by #56
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@ruimo
Copy link

ruimo commented May 26, 2020

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
[]
@harawata harawata transferred this issue from mybatis/mybatis-3 May 27, 2020
@kazuki43zoo kazuki43zoo self-assigned this May 27, 2020
@kazuki43zoo kazuki43zoo added the bug Something isn't working label May 27, 2020
@kazuki43zoo kazuki43zoo added this to the 1.0.2 milestone May 27, 2020
@kazuki43zoo
Copy link
Member

@ruimo Thanks for your reporting!!

I've investigated this behavior. This behavior is bug when use together with Spring Boot FatJar.
The Resources.getResourceAsFile(actualPath).exists() return false always on Spring Boot FatJar.
I will change that not call the File#exists.

@kazuki43zoo
Copy link
Member

Hi @ruimo ,

I've fixed this and publish the 1.0.2-SNAPSHOT version on "Sonatype OSS Snapshots Repository". Please try it when you have a time!!

You should add maven repository setting and modify dependency version as follow:

repositories {
    mavenCentral()
    mavenLocal()
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" } // Add this line
}
dependencies {
    // ...
    implementation "org.mybatis.scripting:mybatis-thymeleaf:1.0.2-SNAPSHOT" // Modify this line
    // ...
}

Also, I've fixed same issue on https://github.com/mybatis/freemarker-scripting .

@ruimo
Copy link
Author

ruimo commented May 28, 2020

It worked like a charm! Thank you for your support.

@kazuki43zoo kazuki43zoo changed the title SQL template file not found in case the application is embeded in spring boot jar file. SQL template file not found in case the application is embedded in spring boot jar file Jun 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants