MyBatis the reason and solution of infinite output log of console at startup _java

Source: Internet
Author: User
Tags log4j

Have you encountered the following situation, 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 only occurs if it is integrated with spring.

Every time this error occurs, I know that XML is wrong, but the exact XML is not directly validated, because the logs here do not see any useful information.

To locate this error, I have a common approach, which is to start one of the entry breakpoints from the program and then step through the error.

But this way is still very troublesome, here to say is a rapid positioning solution, easy to operate.

Find the Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory class, in the following ways:

protected void Autowirebytype (
String beanname, abstractbeandefinition mbd, beanwrapper bw, mutablepropertyvalues PVS) {
This method is about 1200 lines. Locate the catch exception in this method:
catch (Beansexception ex) {
throw new unsatisfieddependencyexception ( Mbd.getresourcedescription (), Beanname, PropertyName, ex);

In throw this line of breakpoints, this place is the first place to catch the exception, when the Mapper.xml file error, the exception information here is as follows:

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 very silent error:

Do not know what the beginning of the Emplo, basically as long as the XML in what is wrong, are similar to the exception information, is generally XML parse out of the error.

There is also a problem, why the error can only see an infinite output of a row of logs, and can not see the specific exception information here?

By tracking the code, you find 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); C6/>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, direct return null causes the exception to be swallowed.

Since this is where the last layer catches the anomaly, and the area of the exception that is caught in this area will be wider, it is also a good choice to view the breakpoint here, as the real error message is hidden deep in the following image:

See here, I believe this problem should be easy to solve.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.