In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "spring boot2 embedded Tomcat throw exception how to solve", the article explains the content is simple and clear, easy to learn and understand, now please follow the editor's train of thought slowly in depth, together to study and learn "spring boot2 embedded Tomcat throw exception how to solve" it!
When I was using springboot, when there was something wrong with the code, I found that the console printed the following information:
Connected to the target VM, address: '127.0.0.1 transport 42091, transport:' socket'log4j:WARN No appenders could be found for logger (org.springframework.boot.devtools.settings.DevToolsSettings). Log4j:WARN Please initialize the log4j system properly.log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. . _ _ / / _ _ _ (() _ _ _ |'_ _ _ | |\ / _ _ _ | | | (_ _ | |) )'| _ |. _ _ | _ | | _ | _ | | _\ _ _ | | / = | _ | = | _ _ / = / _ /:: Spring Boot:: (v2.0.6.RELEASE) 2018-10-25 10 INFO 102158-- [restartedMain] o.apache.catalina.core.StandardService: Starting service [Tomcat] 2018-10-25 10 INFO Starting Servlet Engine 102158-[restartedMain] org.apache.catalina.core.StandardEngine: Starting Servlet Engine: Apache Tomcat | / 8.5.342018-10-25 10 The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path 10 o.a.catalina.core.AprLifecycleListener 21.444 INFO 102158-[ost-startStop-1] o.a.catalina.core.AprLifecycleListener: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/ usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib] 2018-10-25 10 o.a.catalina.core.AprLifecycleListener 10 Swiss 21.590 INFO 102158-[ost-startStop-1] O.a.c.c. [tomcat] .[ localhost]. [/]: Initializing Spring embedded WebApplicationContext2018-10-25 10 restartedMain 10 o.apache.catalina.core.StandardService: Stopping service [tomcat] host 102158-[tomcat] host: tomcat]. [localhost]. Address: '127.0.0.1 virtual 42091, transport:' socket'Process finished with exit code 0
WTF? How can I solve the problem without error messages? All kinds of search, in short, there is something wrong with the code, check it yourself.
All right, just debug
The entry class with embedded tomcat is org.apache.catalina.core.StandardService
/ / make-up process after TODO
Finally find the org.springframework.context.support.AbstractApplicationContext location method refresh ()
If (logger.isWarnEnabled ()) {logger.warn ("Exception encountered during context initialization -" + "cancelling refresh attempt:" + ex);}
Debug can enter normally, and then we can see the ex we want to see.
Org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fabricApiController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name' fabricTemplate': Injection of resource dependencies failed; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'fabricConfiguration': Could not bind properties to' FabricConfiguration': prefix=blockchain, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'blockchain.channel-peers' to java.util.List
The problem is found, solve your own code problem, and then restart, normal! All is well? No, it's just the beginning.
Above we simply solved the problem, but the root cause has not been solved! To say that the solution briefly describes the current popular log system, the source network is sorted out as follows: common log framework, note that it is not the facade interface of the log provided by Commons-logging: apache, the first solution. Avoid direct coupling with specific logging schemes. Similar to the api interface of JDBC, the specific JDBC driver implementation is implemented by each database provider. Decoupled through a unified interface, but its internal implementation of some simple logging scheme 2 Slf4j: the full name is Simple Logging Facade for JAVA:java simple log facade. Is a facade package for different logging frameworks. You can access a logging implementation without modifying any configuration at deployment time. Should have the same original intention as commons-loging. Common logging implementation: the detailed pros and cons of log4jlogbackjdk-logging are not the focus of this article, please search by yourself.
Then analyze the above problems, Commons-logging is the default log system of tomcat (apache has to support its own things), the specific log implementation, according to the existing log system choice. Briefly list the following log implementations: org.apache.commons.logging.Log | org.apache.commons.logging.impl.SimpleLog org.apache.commons.logging.impl.NoOpLog org.apache.commons.logging.impl.Log4JLogger org.apache.commons.logging.impl.SLF4JLog org.apache.commons.logging.impl.Jdk14Logger
Springboot uses the logback logging implementation by default, and that's the problem! Common-logs does not have an implementation of logback!
Based on the maven dependency, we see that both log4j and logback packages have been introduced, and then tomcat can choose log4j,springboot to use logback. Log4j and logback only see the lack of a bridge, it is the lack of this bridge, resulting in springboot can only output logbacklinks!
The bridge in the middle is the following dependence
Org.slf4j jcl-over-slf4j
This dependency outputs log4j to slf4j, which in turn outputs from sl4j.
Summary: to sum up, it is clear that it is the feud between slf4j/common-logs log4j and logback.
The first solution: locate the problem according to the log, then use addition processing, add jcl-over-slf4j, and open slf4j and common-logs channels.
The second solution: to resolve the conflict, there is no room for two tigers in one mountain, exclude either side of slf4j,common-logs, and spring uses slf4j, then you can rule out calling common-logs.
Thank you for reading, the above is the content of "how to solve the exception thrown by spring boot2 embedded Tomcat". After the study of this article, I believe you have a deeper understanding of how to solve this problem with spring boot2 embedded Tomcat throwing exception, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.