spring boot embedded Tomcat thrown "Stopping service [Tomcat]"

When I use springboot, when the code has a problem, find the console prints the following information:

Connected to the target VM, address: '127.0.0.1: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:10:21.425  INFO 102158 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-10-25 10:10:21.427  INFO 102158 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.34
2018-10-25 10:10: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:10:21.590  INFO 102158 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-10-25 10:10:24.522  INFO 102158 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
Disconnected from the target VM, address: '127.0.0.1:42091', transport: 'socket'

Process finished with exit code 0

WTF? No error message is how to solve the problem? A variety of search, in short, is the code in question, check for yourself the ...

Well, the direct debug

Tomcat is embedded in the entrance classorg.apache.catalina.core.StandardService

// TODO back up the process

Eventually find a org.springframework.context.support.AbstractApplicationContext location methodrefresh()

if (logger.isWarnEnabled()) {
				logger.warn("Exception encountered during context initialization - " +
						"cancelling refresh attempt: " + ex);
			}

debug can normally enter, and then you see we want to see the ex

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<com.smy.bc.fabric.core.configuration.FabricConfiguration$EndPoint>

Problems found, the code to solve their own problems, then restart, normal! Everything is all right? Wrong, this began

上面我们简单解决了问题,但是根源没有解决!
要说解决方案把当前流行的日志体系简单说一遍
下面整理的来源网络:

常见的日志框架,注意不是具体解决方案

1 Commons-logging: apache 最早提供的日志的门面接口。避免和具体的日志方案直接耦合。类似于JDBC的api接口,具体的的JDBC driver实现由各数据库提供商实现。通过统一接口解耦,不过其内部也实现了一些简单日志方案
2 Slf4j: 全称为Simple Logging Facade for JAVA:java简单日志门面。是对不同日志框架提供的一个门面封装。可以在部署的时候不修改任何配置即可接入一种日志实现方案。和commons-loging应该有一样的初衷。

常见的日志实现:
log4j
logback
jdk-logging

详细优缺点不是本文重点,请自行搜索。

Then analyzes the above problems, Commons-logging is the default logging system tomcat (apache have to support their own thing), specific logging implementation, system selection according to the log system already exists. Simply include 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 default is logback logging implementation, the question arises here! ! ! common-logs did not realize the logback!

According maven dependency, we see log4j and logback packages are introduced, then it can choose the tomcat log4j, springboot using logback. log4j and logback saw the lack of a bridge, is the lack of this bridge, the output can only lead to springboot logback! ! !

The middle of the bridge is dependent on the following

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
    </dependency>

This dependence can be output to log4j slf4j, so that the output from the sl4j.

Summary: In summary, already thoroughly understand slf4j / common-logs <> log4j and logback exact revenge

The first solution: The positioning of the log, and then addition processing using increased jcl-over-slf4j, open channel common-logs and slf4j

The second solution: to resolve the conflict, the mountain can not be two tigers, excluded slf4j, common-logs either, spring use slf4j, it can be adjusted to exclude common-logs

From the perspective of the optimization program, the second and more preferably, to reduce unnecessary dependencies.

If the log problems that logs system conflicts, and can refer to this idea, the project log processing abnormalities.

Published 23 original articles · won praise 7 · views 20000 +

Guess you like

Origin blog.csdn.net/ghd602338792/article/details/104949990