Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of sqlSessionFactory injection Mode of MapperScannerConfigurer

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the example analysis of sqlSessionFactory injection mode of MapperScannerConfigurer, which is very detailed and has certain reference value. Friends who are interested must read it!

Explanation of sqlSessionFactory injection method of MapperScannerConfigurer

First of all, there is a section of configuration in Mybatis that is very convenient, saving us the time to write DaoImpl (Dao layer implementation class). This configuration is package scanning.

Let's look at a piece of code first:

In MapperScannerConfigurer, we know that there are four ways to inject sqlSessionFactory, which is sqlSessionFactory,sqlSessionFactoryBeanName,sqlSessionTemplate,sqlSessionTemplateBeanName, and sqlSessionFactory is out of date, so we use sqlSessionFactoryBeanName, so let's talk about the benefits of this and why we use it!

Reason 1:

When sqlSessionFactory is injected (not configured) only when multiple data sources are configured, there will be multiple sqlSessionFactory. Which sqlSessionFactory can be specified by changing the attribute (summary on the integrated network)

Reason 2 (key):

After injecting sqlSessionFactory, the value is the name of the bean of SqlSessionFactory, that is, the id of sqlSessionFactory. When our mapperscannerconfigurer starts, it may appear that our jdbc.properties file has not been loaded, so the DataSource it gets is wrong, because attributes like ${jdbc.url} have not been replaced, so through BeanName post-processing, when we use our Mybatis, it will go to our corresponding sqlSessionFactory. To prevent it from initializing our sqlSessionFactory.

The above is all the contents of the article "sample Analysis of sqlSessionFactory injection methods of MapperScannerConfigurer". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report