Recently in a Sb+tkmybatis integration can provide a common data interface of the demo, but there is a very strange thing. Use the Selectbyprimarykey interface provided by Mapper to return the result times exception:
Java.lang.ClassCastException:com.yhq.ssmdemo.web.mysql.pojo.Tree cannot is cast to Com.yhq.ssmdemo.web.mysql.pojo.Trees
... What the heck? Self-transformation yourself? Also reported abnormal? Engaged in a whole day do not know how to go to see MyBatis source code, Mapper source, did not find that will cause this kind of problem codes. And then, in another demo without Springboot, there's no such thing as an interview. Then I started to study whether Spring boot auto-configuration was missing something, but I didn't find it, and it wouldn't be the problem ... Then after the Internet search (before the search, but may not be accurate keyword search results), and then found a similar problem, said this is a tool caused by a bug, but I thought it was the Mapper tool, looked at the solution he gave to know is spring Devtools this tool. Because it was developed locally, the Spring Devtools tool was used to monitor the code modification automatic Restart, we know that the principle of this tool is to use two class loader, one load does not change the third party's dependency jar, and another to load their own project in the written class. So this anomaly is caused by this problem, which can be seen more clearly and intuitively,
This is a diagram of the heap dump when the project starts the Spring Devtools module, and I can see that many of the classes I write myself have two:
This is the project does not enable the Spring devtools module heap dump diagram, the class wrote only one:
So this is entirely the result of the use of spring devtools, how to solve it? Let the same ClassLoader load the Mapper jar and the entity class that you write:
Create a new directory under the Src/main/resources directory for the project: Meta-inf, and then create a new Spring-devtools.properties file with the contents: Restart.include.companycommonlibs=tk/mybatis.* can be.
Spring Boot+tkmybatis (Mapper) tool implements common data manipulation interface problems