Have you encountered the following situation where the console unlimited output of the following log:
Logging initialized using 'class org.apache.ibatis.logging.log4j.Log4jImpl' adapter.
Logging initialized using 'class org.apache.ibatis.logging.log4j.Log4jImpl' adapter.
Logging initialized using 'class org.apache.ibatis.logging.log4j.Log4jImpl' adapter.
Logging initialized using 'class org.apache.ibatis.logging.log4j.Log4jImpl' adapter.
Logging initialized using 'class org.apache.ibatis.logging.log4j.Log4jImpl' adapter.
This error will only occur if integrated with Spring.
Every time this error occurs, I know that the XML error occurs, but the specific XML cannot be confirmed directly, because the log here cannot see any useful information.
If you want to locate this error, I have a common method, which is to gradually locate this error from a certain entry breakpoint in the program startup.
However, this method is still very troublesome. What I want to talk about here is a quick positioning solution, which is very simple to operate.
Find the org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory class, in the following method:
protected void autowireByType(String beanName, AbstractBeanDefinition mbd, BeanWrapper bw, MutablePropertyValues pvs) {This method is about 1200 lines. Find the place where the catch exception in this method: catch (BeansException ex) {throw new UnsatisfiedDependencyException(mbd.getResourceDescription(), beanName, propertyName, ex);}Just breakpoint on the throw line. This place is the first place to catch exceptions. When the Mapper.xml file errors, the exception information here is as follows:
The exception information is very detailed, the specific exception text is as follows:
org.springframework.core.NestedIOException:
Failed to parse mapping resource:
'file [F:/Liu/Git/bhgl/target/Franchisee-1.0/WEB-INF/classes/com/abel533/property/dao/EmployeeMapper.xml]';
nested exception is org.apache.ibatis.builder.BuilderException:
Error creating document instance.
Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in the preface.
After opening this error XML, I found a speechless error:
I don’t know what the situation is, there is an emplo at the beginning. Basically, as long as there is any error in XML, it is similar exception information, and it is generally an error in XML parsing.
There is another question, why can only see one line of logs with infinite output after an error, but cannot see the specific exception information here?
By following the code, I found the method 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 catching the exception here, return null directly causes the exception to be swallowed.
Since this is the last layer where exceptions are caught, and the exceptions caught in this place will be wider, it is also a good choice to view problems at breakpoints here. Since it has been processed through multiple layers of exceptions, the real error information is hidden deep, as shown in the figure below:
Seeing this, I believe this problem will be easily solved when I encounter it again.