In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "how to solve the TypeAlias problem of loading Mybatis based on SpringBoot". The editor shows you the operation process through an actual case, the operation method is simple and fast, and it is practical. I hope that this article "how to solve the TypeAlias problem of loading Mybatis based on SpringBoot" can help you solve the problem.
SpringBoot loads TypeAlias of Mybatis
After springboot is typed as jar, running on linux will report the problem that the entity class corresponding to type alias cannot be found. This is the problem of springboot scanning packages.
The DefaultVFS of Mybatis is used by default in the project, but in the environment of springboot, there will be problems with the DefaultVFS of Mybatis, so you can only modify VFS in order to be clearly visible.
Directly post the code: @ Bean public SqlSessionFactory sqlSessionFactoryBean () throws Exception {logger.info ("load SpringBootVFS"); / / DefaultVFS has a problem in obtaining jar. Using springboot can only modify VFS.addImplClass (SpringBootVFS.class); SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean (); sqlSessionFactoryBean.setDataSource (dataSource ()); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver (); Resource [] resources1 = resolver.getResources ("classpath*:/mybatis/*.xml") Resource [] resources2 = resolver.getResources ("classpath*:/mysql/mapper/*.xml"); Resource [] resources = (Resource []) ArrayUtils.addAll (resources1,resources2); sqlSessionFactoryBean.setMapperLocations (resources); sqlSessionFactoryBean.setTypeAliasesPackage ("com.xxx.xx.entity"); return sqlSessionFactoryBean.getObject ();} springboot packages errors that cannot be found in the typeAlias class name of the startup times mybatis
The springBoot project works well on IDEA, but there is an error running after packaging. The error is roughly that typeAlias cannot find the XX class when mybatis parses Mapper.xml.
The tag in Mapper:
This way of writing works in IDEA. If there is no problem, there is a problem with packaging.
Write it correctly:
The parameterType in the code must use the full path or there will be an error.
This is the end of the content on "how to solve the TypeAlias problem of loading Mybatis based on SpringBoot". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.