忘记,模糊,故专门验证下
比如方法1调用方法2
方法2又调用方法3
方法3报错
那么报错日志中哪个方法所在行先打印出来?
直接上测试代码
package pers.wwz.study.exception.controller;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.PostConstruct;
@Slf4j
@RestController
@RequestMapping("/exception")
public class ExceptionController {
@PostConstruct
@RequestMapping("/test")
public void test(){
log.info("调用接口:{}","/exception/test");
testException1();
}
public void testException1(){
log.info("调用testException1");
testException2();
}
public void testException2(){
log.info("调用testException2");
System.out.println(1/0);
}
}
完整日志
D:\softwares\jdk\jdk8\jdk1.8.0_351\bin\java.exe -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:50440,suspend=y,server=n -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-Dmanagement.endpoints.jmx.exposure.include=*" -javaagent:C:\Users\Mayn\AppData\Local\JetBrains\IntelliJIdea2022.3\captureAgent\debugger-agent.jar -Dfile.encoding=UTF-8 -classpath "D:\softwares\jdk\jdk8\jdk1.8.0_351\jre\lib\charsets.jar;D:\softwares\jdk\jdk8\jdk1.8.0_351\jre\lib\deploy.jar;D:\softwares\jdk\jdk8\jdk1.8.0_351\jre\lib\ext\access-bridge-64.jar;D:\softwares\jdk\jdk8\jdk1.8.0_351\jre\lib\ext\cldrdata.jar;D:\softwares\jdk\jdk8\jdk1.8.0_351\jre\lib\ext\dnsns.jar;D:\softwares\jdk\jdk8\jdk1.8.0_351\jre\lib\ext\jaccess.jar;D:\softwares\jdk\jdk8\jdk1.8.0_351\jre\lib\ext\jfxrt.jar;D:\softwares\jdk\jdk8\jdk1.8.0_351\jre\lib\ext\localedata.jar;D:\softwares\jdk\jdk8\jdk1.8.0_351\jre\lib\ext\nashorn.jar;D:\softwares\jdk\jdk8\jdk1.8.0_351\jre\lib\ext\sunec.jar;D:\softwares\jdk\jdk8\jdk1.8.0_351\jre\lib\ext\sunjce_provider.jar;D:\softwares\jdk\jdk8\jdk1.8.0_351\jre\lib\ext\sunmscapi.jar;D:\softwares\jdk\jdk8\jdk1.8.0_351\jre\lib\ext\sunpkcs11.jar;D:\softwares\jdk\jdk8\jdk1.8.0_351\jre\lib\ext\zipfs.jar;D:\softwares\jdk\jdk8\jdk1.8.0_351\jre\lib\javaws.jar;D:\softwares\jdk\jdk8\jdk1.8.0_351\jre\lib\jce.jar;D:\softwares\jdk\jdk8\jdk1.8.0_351\jre\lib\jfr.jar;D:\softwares\jdk\jdk8\jdk1.8.0_351\jre\lib\jfxswt.jar;D:\softwares\jdk\jdk8\jdk1.8.0_351\jre\lib\jsse.jar;D:\softwares\jdk\jdk8\jdk1.8.0_351\jre\lib\management-agent.jar;D:\softwares\jdk\jdk8\jdk1.8.0_351\jre\lib\plugin.jar;D:\softwares\jdk\jdk8\jdk1.8.0_351\jre\lib\resources.jar;D:\softwares\jdk\jdk8\jdk1.8.0_351\jre\lib\rt.jar;D:\my_projects\springboot-exception-20230810\springboot-exception\target\classes;C:\Users\Mayn\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.7.14\spring-boot-starter-web-2.7.14.jar;C:\Users\Mayn\.m2\repository\org\springframework\boot\spring-boot-starter\2.7.14\spring-boot-starter-2.7.14.jar;C:\Users\Mayn\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.7.14\spring-boot-starter-logging-2.7.14.jar;C:\Users\Mayn\.m2\repository\ch\qos\logback\logback-classic\1.2.12\logback-classic-1.2.12.jar;C:\Users\Mayn\.m2\repository\ch\qos\logback\logback-core\1.2.12\logback-core-1.2.12.jar;C:\Users\Mayn\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.17.2\log4j-to-slf4j-2.17.2.jar;C:\Users\Mayn\.m2\repository\org\apache\logging\log4j\log4j-api\2.17.2\log4j-api-2.17.2.jar;C:\Users\Mayn\.m2\repository\org\slf4j\jul-to-slf4j\1.7.36\jul-to-slf4j-1.7.36.jar;C:\Users\Mayn\.m2\repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;C:\Users\Mayn\.m2\repository\org\yaml\snakeyaml\1.30\snakeyaml-1.30.jar;C:\Users\Mayn\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.7.14\spring-boot-starter-json-2.7.14.jar;C:\Users\Mayn\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.13.5\jackson-databind-2.13.5.jar;C:\Users\Mayn\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.13.5\jackson-annotations-2.13.5.jar;C:\Users\Mayn\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.13.5\jackson-core-2.13.5.jar;C:\Users\Mayn\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.13.5\jackson-datatype-jdk8-2.13.5.jar;C:\Users\Mayn\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.13.5\jackson-datatype-jsr310-2.13.5.jar;C:\Users\Mayn\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.13.5\jackson-module-parameter-names-2.13.5.jar;C:\Users\Mayn\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.7.14\spring-boot-starter-tomcat-2.7.14.jar;C:\Users\Mayn\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.78\tomcat-embed-core-9.0.78.jar;C:\Users\Mayn\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.78\tomcat-embed-el-9.0.78.jar;C:\Users\Mayn\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.78\tomcat-embed-websocket-9.0.78.jar;C:\Users\Mayn\.m2\repository\org\springframework\spring-web\5.3.29\spring-web-5.3.29.jar;C:\Users\Mayn\.m2\repository\org\springframework\spring-beans\5.3.29\spring-beans-5.3.29.jar;C:\Users\Mayn\.m2\repository\org\springframework\spring-webmvc\5.3.29\spring-webmvc-5.3.29.jar;C:\Users\Mayn\.m2\repository\org\springframework\spring-aop\5.3.29\spring-aop-5.3.29.jar;C:\Users\Mayn\.m2\repository\org\springframework\spring-context\5.3.29\spring-context-5.3.29.jar;C:\Users\Mayn\.m2\repository\org\springframework\spring-expression\5.3.29\spring-expression-5.3.29.jar;C:\Users\Mayn\.m2\repository\org\springframework\boot\spring-boot-devtools\2.7.14\spring-boot-devtools-2.7.14.jar;C:\Users\Mayn\.m2\repository\org\springframework\boot\spring-boot\2.7.14\spring-boot-2.7.14.jar;C:\Users\Mayn\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.7.14\spring-boot-autoconfigure-2.7.14.jar;C:\Users\Mayn\.m2\repository\org\projectlombok\lombok\1.18.28\lombok-1.18.28.jar;C:\Users\Mayn\.m2\repository\org\slf4j\slf4j-api\1.7.36\slf4j-api-1.7.36.jar;C:\Users\Mayn\.m2\repository\org\springframework\spring-core\5.3.29\spring-core-5.3.29.jar;C:\Users\Mayn\.m2\repository\org\springframework\spring-jcl\5.3.29\spring-jcl-5.3.29.jar;D:\softwares\IntelliJ IDEA 2022.3\lib\idea_rt.jar" pers.wwz.study.exception.SpringbootExceptionApplication
Connected to the target VM, address: '127.0.0.1:50440', transport: 'socket'
11:07:07.337 [Thread-6] DEBUG org.springframework.boot.devtools.restart.classloader.RestartClassLoader - Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@32e21244
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.14)
2023-08-10 11:07:21.258 INFO 20336 --- [ restartedMain] p.w.s.e.SpringbootExceptionApplication : Starting SpringbootExceptionApplication using Java 1.8.0_351 on AscendKing with PID 20336 (D:\my_projects\springboot-exception-20230810\springboot-exception\target\classes started by Mayn in D:\my_projects\springboot-exception-20230810\springboot-exception)
2023-08-10 11:07:21.300 INFO 20336 --- [ restartedMain] p.w.s.e.SpringbootExceptionApplication : No active profile set, falling back to 1 default profile: "default"
2023-08-10 11:07:23.821 INFO 20336 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2023-08-10 11:07:23.821 INFO 20336 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2023-08-10 11:07:45.356 INFO 20336 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2023-08-10 11:07:45.557 INFO 20336 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2023-08-10 11:07:45.557 INFO 20336 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.78]
2023-08-10 11:07:46.558 INFO 20336 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2023-08-10 11:07:46.558 INFO 20336 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 22725 ms
2023-08-10 11:07:48.094 INFO 20336 --- [ restartedMain] p.w.s.e.controller.ExceptionController : 调用接口:/exception/test
2023-08-10 11:07:48.119 INFO 20336 --- [ restartedMain] p.w.s.e.controller.ExceptionController : 调用testException1
2023-08-10 11:07:48.119 INFO 20336 --- [ restartedMain] p.w.s.e.controller.ExceptionController : 调用testException2
2023-08-10 11:07:48.188 WARN 20336 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'exceptionController': Invocation of init method failed; nested exception is java.lang.ArithmeticException: / by zero
2023-08-10 11:07:48.300 INFO 20336 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2023-08-10 11:07:48.639 INFO 20336 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-08-10 11:07:49.284 ERROR 20336 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'exceptionController': Invocation of init method failed; nested exception is java.lang.ArithmeticException: / by zero
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:160) ~[spring-beans-5.3.29.jar:5.3.29]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:440) ~[spring-beans-5.3.29.jar:5.3.29]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796) ~[spring-beans-5.3.29.jar:5.3.29]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.29.jar:5.3.29]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.29.jar:5.3.29]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.29.jar:5.3.29]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.29.jar:5.3.29]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.29.jar:5.3.29]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.29.jar:5.3.29]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955) ~[spring-beans-5.3.29.jar:5.3.29]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:921) ~[spring-context-5.3.29.jar:5.3.29]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.29.jar:5.3.29]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.14.jar:2.7.14]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731) [spring-boot-2.7.14.jar:2.7.14]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) [spring-boot-2.7.14.jar:2.7.14]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-2.7.14.jar:2.7.14]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303) [spring-boot-2.7.14.jar:2.7.14]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292) [spring-boot-2.7.14.jar:2.7.14]
at pers.wwz.study.exception.SpringbootExceptionApplication.main(SpringbootExceptionApplication.java:10) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_351]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_351]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_351]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_351]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:50) [spring-boot-devtools-2.7.14.jar:2.7.14]
Caused by: java.lang.ArithmeticException: / by zero
at pers.wwz.study.exception.controller.ExceptionController.testException2(ExceptionController.java:31) ~[classes/:na]
at pers.wwz.study.exception.controller.ExceptionController.testException1(ExceptionController.java:25) ~[classes/:na]
at pers.wwz.study.exception.controller.ExceptionController.test(ExceptionController.java:19) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_351]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_351]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_351]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_351]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:389) ~[spring-beans-5.3.29.jar:5.3.29]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:333) ~[spring-beans-5.3.29.jar:5.3.29]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:157) ~[spring-beans-5.3.29.jar:5.3.29]
... 23 common frames omitted
Disconnected from the target VM, address: '127.0.0.1:50440', transport: 'socket'
Process finished with exit code 0
经过验证是最终调用的方法所在行先打印出来