Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem that mybatis keeps loading xml

Shulou Source: shulou.com Published: 2022-06-01 18:52:42 09月29日 Update

This article mainly explains the "mybatis has been loading xml how to solve", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "mybatis has been loading xml how to solve" it!

Mybatis keeps loading xml and finds an error

When we write the springmvc+mybatis project, when we start the project, the mapper configuration file is always brushed and loaded.

For our great programmers, this is not terrible, the terrible thing is that there are no mistakes to print out. I have no idea how to do it.

Today, we finally found a solution.

Find the org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory class and use the following method:

Protected void autowireByType (String beanName, AbstractBeanDefinition mbd, BeanWrapper bw, MutablePropertyValues pvs) {catch (BeansException ex) {throw new UnsatisfiedDependencyException (mbd.getResourceDescription (), beanName, propertyName, ex);}

You can do it at the breakpoint of the throw line, which is the first place to catch exceptions. When there is an error in the Mapper.xml file, the exception information will be output.

There is another question: why can you only see an infinite line of logs after an error, but not the specific exception information here?

By tracing the code, you find the methods in the org.springframework.beans.factory.support.AbstractBeanFactory class:

Protected Class getTypeForFactoryBean (String beanName, RootBeanDefinition mbd) {if (! mbd.isSingleton ()) {return null;} try {FactoryBean factoryBean = doGetBean (FACTORY_BEAN_PREFIX + beanName, FactoryBean.class, null, true); return getTypeForFactoryBean (factoryBean);} catch (BeanCreationException ex) {/ / Can only happen when getting a FactoryBean. If (logger.isDebugEnabled ()) {logger.debug ("Ignoring bean creation exception on FactoryBean type check:" + ex);} onSuppressedException (ex); return null;}}

After the exception is caught here, the direct return null causes the exception to be swallowed.

Mybatis lazy loading (xml)

For one-to-one and many-to-one (mybatis maps to one-to-one). When querying, you can query together.

But for one-to-many and many-to-many. Maybe there is a lot of data corresponding to that much, and we don't need that much. Then querying together will waste performance resources.

So, mybatis has lazy loading.

Mysql loads immediately by default.

Lazy loading has a fetchType property in the Collection or association property, and eager loads immediately. Lazy loads lazily.

In the mybatis configuration file, thank you for reading, the above is "mybatis has been loading xml how to solve" the content, after the study of this article, I believe you have a deeper understanding of how mybatis has been loading xml to solve this problem, the specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: File method time learning query scary one-on-one line information content place property error problem project output configuration greatness code that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Docker Apple Shulou Information Shulou Tech Info