大家好,又见面了,我是你们的朋友全栈君。
首先声明一下,我用的 Intellij IDEA 2018.3 版本的,springboot的版本是 2.0.5.RELEASE 版本。
当我喜滋滋的编写完测试代码,点击 Debug 的时候,睁大眼睛看控制台简直是看得一脸懵逼,控制台显示如下:
代码语言:javascript复制SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
. ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _
( ( )___ | '_ | '_| | '_ / _` |
\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |___, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.5.RELEASE)
十二月 13, 2018 4:48:04 下午 org.apache.catalina.core.StandardService startInternal
信息: Starting service [Tomcat]
十二月 13, 2018 4:48:04 下午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/8.5.34
十二月 13, 2018 4:48:04 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [D:Program Filesjavajdk1.8bin;C:WINDOWSSunJavabin;C:WINDOWSsystem32;C:WINDOWS;C:ProgramDataOracleJavajavapath;C:Program Files (x86)Common FilesNetSarang;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32WindowsPowerShellv1.0;C:Program Files (x86)ATI TechnologiesATI.ACECore-Static;D:Program Filesjavajdk1.7bin;D:Program Filesmysql-5.7.17bin;C:WINDOWSSystem32OpenSSH;D:Program FilesGitcmd;D:Program FilesTortoiseSVNbin;C:UsersAdministratorAppDataLocalMicrosoftWindowsApps;;.]
十二月 13, 2018 4:48:05 下午 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring embedded WebApplicationContext
没错,就是这么点日志,但是注意 第一行 SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”.
然后去 http://www.slf4j.org/codes.html#StaticLoggerBinder 地址看了下解决方法,这里我就不详细说了,反正大概意思就加上slf4j-nop.jar slf4j-simple.jar, slf4j-log4j12.jar,slf4j-jdk14.jar或 logback-classic.jar中的其中一个jar包就行(只能是一个,多了就会有冲突)。
于是乎我加了 slf4j-simple jar包代码如下:(这段代码是我直接从线上maven库中copy出来的,肯定不会有错)
代码语言:javascript复制<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
<scope>test</scope>
</dependency>
引入依赖后,启动还是报错,一模一样,这TM就有点过分了,官网的解决方法一般是不会出错的,而且之前我也百度过,也是差不多一样的做法,那到底是什么问题呢?
于是又是一顿找,看看前辈们有没有碰到过类似的错误,终于有所发现,最终修改代码如下:
代码语言:javascript复制<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
<scope>compile</scope>
</dependency>
没错,就是毁在这段代码上 <scope>test</scope> ,test表示只有在测试环境下,才可以使用,而我springboot是运行在main方法中,是不属于测试环境,所以这个包就相当于没有加入依赖,也就没有被加载到。改成compile则表示编译的时候就会加载此jar包,那么最后就运行成功了,成功的日志如下:
代码语言:javascript复制"D:Program Filesjavajdk1.8binjava.exe" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:51555,suspend=y,server=n -javaagent:C:UsersAdministrator.IntelliJIdea2018.3systemcaptureAgentdebugger-agent.jar -Dfile.encoding=UTF-8 -classpath "D:Program Filesjavajdk1.8jrelibcharsets.jar;D:Program Filesjavajdk1.8jrelibdeploy.jar;D:Program Filesjavajdk1.8jrelibextaccess-bridge-64.jar;D:Program Filesjavajdk1.8jrelibextcldrdata.jar;D:Program Filesjavajdk1.8jrelibextdnsns.jar;D:Program Filesjavajdk1.8jrelibextjaccess.jar;D:Program Filesjavajdk1.8jrelibextjfxrt.jar;D:Program Filesjavajdk1.8jrelibextlocaledata.jar;D:Program Filesjavajdk1.8jrelibextnashorn.jar;D:Program Filesjavajdk1.8jrelibextsunec.jar;D:Program Filesjavajdk1.8jrelibextsunjce_provider.jar;D:Program Filesjavajdk1.8jrelibextsunmscapi.jar;D:Program Filesjavajdk1.8jrelibextsunpkcs11.jar;D:Program Filesjavajdk1.8jrelibextzipfs.jar;D:Program Filesjavajdk1.8jrelibjavaws.jar;D:Program Filesjavajdk1.8jrelibjce.jar;D:Program Filesjavajdk1.8jrelibjfr.jar;D:Program Filesjavajdk1.8jrelibjfxswt.jar;D:Program Filesjavajdk1.8jrelibjsse.jar;D:Program Filesjavajdk1.8jrelibmanagement-agent.jar;D:Program Filesjavajdk1.8jrelibplugin.jar;D:Program Filesjavajdk1.8jrelibresources.jar;D:Program Filesjavajdk1.8jrelibrt.jar;E:IdeaProjectsmiaoshatargetclasses;E:repositoryorgspringframeworkbootspring-boot-starter-web2.0.5.RELEASEspring-boot-starter-web-2.0.5.RELEASE.jar;E:repositoryorgspringframeworkbootspring-boot-starter2.0.5.RELEASEspring-boot-starter-2.0.5.RELEASE.jar;E:repositoryorgspringframeworkbootspring-boot2.0.5.RELEASEspring-boot-2.0.5.RELEASE.jar;E:repositoryorgspringframeworkbootspring-boot-autoconfigure2.0.5.RELEASEspring-boot-autoconfigure-2.0.5.RELEASE.jar;E:repositoryorgspringframeworkbootspring-boot-starter-logging2.0.5.RELEASEspring-boot-starter-logging-2.0.5.RELEASE.jar;E:repositoryorgapachelogginglog4jlog4j-to-slf4j2.10.0log4j-to-slf4j-2.10.0.jar;E:repositoryorgapachelogginglog4jlog4j-api2.10.0log4j-api-2.10.0.jar;E:repositoryorgslf4jjul-to-slf4j1.7.25jul-to-slf4j-1.7.25.jar;E:repositoryjavaxannotationjavax.annotation-api1.3.2javax.annotation-api-1.3.2.jar;E:repositoryorgspringframeworkspring-core5.0.9.RELEASEspring-core-5.0.9.RELEASE.jar;E:repositoryorgspringframeworkspring-jcl5.0.9.RELEASEspring-jcl-5.0.9.RELEASE.jar;E:repositoryorgyamlsnakeyaml1.19snakeyaml-1.19.jar;E:repositoryorgspringframeworkbootspring-boot-starter-json2.0.5.RELEASEspring-boot-starter-json-2.0.5.RELEASE.jar;E:repositorycomfasterxmljacksoncorejackson-databind2.9.6jackson-databind-2.9.6.jar;E:repositorycomfasterxmljacksoncorejackson-annotations2.9.0jackson-annotations-2.9.0.jar;E:repositorycomfasterxmljacksoncorejackson-core2.9.6jackson-core-2.9.6.jar;E:repositorycomfasterxmljacksondatatypejackson-datatype-jdk82.9.6jackson-datatype-jdk8-2.9.6.jar;E:repositorycomfasterxmljacksondatatypejackson-datatype-jsr3102.9.6jackson-datatype-jsr310-2.9.6.jar;E:repositorycomfasterxmljacksonmodulejackson-module-parameter-names2.9.6jackson-module-parameter-names-2.9.6.jar;E:repositoryorgspringframeworkbootspring-boot-starter-tomcat2.0.5.RELEASEspring-boot-starter-tomcat-2.0.5.RELEASE.jar;E:repositoryorgapachetomcatembedtomcat-embed-core8.5.34tomcat-embed-core-8.5.34.jar;E:repositoryorgapachetomcatembedtomcat-embed-el8.5.34tomcat-embed-el-8.5.34.jar;E:repositoryorgapachetomcatembedtomcat-embed-websocket8.5.34tomcat-embed-websocket-8.5.34.jar;E:repositoryorghibernatevalidatorhibernate-validator6.0.12.Finalhibernate-validator-6.0.12.Final.jar;E:repositoryjavaxvalidationvalidation-api2.0.1.Finalvalidation-api-2.0.1.Final.jar;E:repositoryorgjbossloggingjboss-logging3.3.2.Finaljboss-logging-3.3.2.Final.jar;E:repositorycomfasterxmlclassmate1.3.4classmate-1.3.4.jar;E:repositoryorgspringframeworkspring-web5.0.9.RELEASEspring-web-5.0.9.RELEASE.jar;E:repositoryorgspringframeworkspring-beans5.0.9.RELEASEspring-beans-5.0.9.RELEASE.jar;E:repositoryorgspringframeworkspring-webmvc5.0.9.RELEASEspring-webmvc-5.0.9.RELEASE.jar;E:repositoryorgspringframeworkspring-aop5.0.9.RELEASEspring-aop-5.0.9.RELEASE.jar;E:repositoryorgspringframeworkspring-context5.0.9.RELEASEspring-context-5.0.9.RELEASE.jar;E:repositoryorgspringframeworkspring-expression5.0.9.RELEASEspring-expression-5.0.9.RELEASE.jar;E:repositoryorgslf4jslf4j-simple1.7.25slf4j-simple-1.7.25.jar;E:repositoryorgslf4jslf4j-api1.7.25slf4j-api-1.7.25.jar;D:Program FilesIntelliJ IDEA 2018.3libidea_rt.jar" cn.com.miaosha.App
Connected to the target VM, address: '127.0.0.1:51555', transport: 'socket'
Hello World!
[background-preinit] INFO org.hibernate.validator.internal.util.Version - HV000001: Hibernate Validator 6.0.12.Final
. ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _
( ( )___ | '_ | '_| | '_ / _` |
\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |___, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.5.RELEASE)
[main] INFO cn.com.miaosha.App - Starting App on SC-201806131812 with PID 13188 (E:IdeaProjectsmiaoshatargetclasses started by Administrator in E:IdeaProjectsmiaosha)
[main] INFO cn.com.miaosha.App - No active profile set, falling back to default profiles: default
[main] INFO org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext - Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@36b4fe2a: startup date [Thu Dec 13 17:07:55 CST 2018]; root of context hierarchy
[main] INFO org.springframework.boot.web.embedded.tomcat.TomcatWebServer - Tomcat initialized with port(s): 8080 (http)
十二月 13, 2018 5:08:02 下午 org.apache.catalina.core.StandardService startInternal
信息: Starting service [Tomcat]
十二月 13, 2018 5:08:02 下午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/8.5.34
十二月 13, 2018 5:08:02 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [D:Program Filesjavajdk1.8bin;C:WINDOWSSunJavabin;C:WINDOWSsystem32;C:WINDOWS;C:ProgramDataOracleJavajavapath;C:Program Files (x86)Common FilesNetSarang;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32WindowsPowerShellv1.0;C:Program Files (x86)ATI TechnologiesATI.ACECore-Static;D:Program Filesjavajdk1.7bin;D:Program Filesmysql-5.7.17bin;C:WINDOWSSystem32OpenSSH;D:Program FilesGitcmd;D:Program FilesTortoiseSVNbin;C:UsersAdministratorAppDataLocalMicrosoftWindowsApps;;.]
十二月 13, 2018 5:08:02 下午 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring embedded WebApplicationContext
[localhost-startStop-1] INFO org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 7244 ms
[localhost-startStop-1] INFO org.springframework.boot.web.servlet.ServletRegistrationBean - Servlet dispatcherServlet mapped to [/]
[localhost-startStop-1] INFO org.springframework.boot.web.servlet.FilterRegistrationBean - Mapping filter: 'characterEncodingFilter' to: [/*]
[localhost-startStop-1] INFO org.springframework.boot.web.servlet.FilterRegistrationBean - Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
[localhost-startStop-1] INFO org.springframework.boot.web.servlet.FilterRegistrationBean - Mapping filter: 'httpPutFormContentFilter' to: [/*]
[localhost-startStop-1] INFO org.springframework.boot.web.servlet.FilterRegistrationBean - Mapping filter: 'requestContextFilter' to: [/*]
[main] INFO org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
[main] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter - Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@36b4fe2a: startup date [Thu Dec 13 17:07:55 CST 2018]; root of context hierarchy
[main] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/]}" onto public java.lang.String cn.com.miaosha.App.home(javax.servlet.http.HttpServletRequest)
[main] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
[main] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
[main] INFO org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
[main] INFO org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
[main] INFO org.springframework.jmx.export.annotation.AnnotationMBeanExporter - Registering beans for JMX exposure on startup
[main] INFO org.springframework.boot.web.embedded.tomcat.TomcatWebServer - Tomcat started on port(s): 8080 (http) with context path ''
[main] INFO cn.com.miaosha.App - Started App in 11.308 seconds (JVM running for 14.362)
这日志看上去就正常了。
当然这只是我的解决方法,也许是我的粗心大意吧!如果你也遇到了这种情况可以不妨一试吧。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/186491.html原文链接:https://javaforall.cn