主题:aop执行了2次

aboycdog 2018年11月10日 66

你好, 最近新买了这本书,

我eclipse导入了 https://gitee.com/xiandafu/Spring-Boot-2.0-Samples/tree/master/1_preface/ch1.helloword

这个项目, 执行的时候发现,虽然为http只请求了一次,但是simpleAop里面的内容却执行了2次。

感谢不吝指教


22:26:38.032 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
22:26:38.036 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-starter/target/classes/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter-[\w-]+/, /spring-boot/target/classes/, /spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/]
22:26:38.036 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/home/gausszh/projects/Spring-Boot-2.0-Samples/1_preface/ch1.helloword/target/classes/]

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.0.RELEASE)

2018-11-10 22:26:38.487  INFO 15306 --- [  restartedMain] com.bee.sample.ch1.Ch1Application        : Starting Ch1Application on gausszh with PID 15306 (/home/gausszh/projects/Spring-Boot-2.0-Samples/1_preface/ch1.helloword/target/classes started by gausszh in /home/gausszh/projects/Spring-Boot-2.0-Samples/1_preface/ch1.helloword)
2018-11-10 22:26:38.489  INFO 15306 --- [  restartedMain] com.bee.sample.ch1.Ch1Application        : No active profile set, falling back to default profiles: default
2018-11-10 22:26:38.584  INFO 15306 --- [  restartedMain] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@61b4a1b7: startup date [Sat Nov 10 22:26:38 CST 2018]; root of context hierarchy
2018-11-10 22:26:41.461  INFO 15306 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2018-11-10 22:26:41.495  INFO 15306 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-11-10 22:26:41.495  INFO 15306 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.28
2018-11-10 22:26:41.505  INFO 15306 --- [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-11-10 22:26:41.602  INFO 15306 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-11-10 22:26:41.603  INFO 15306 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3022 ms
2018-11-10 22:26:42.853  INFO 15306 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-11-10 22:26:42.858  INFO 15306 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-11-10 22:26:42.859  INFO 15306 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-11-10 22:26:42.859  INFO 15306 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-11-10 22:26:42.859  INFO 15306 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-11-10 22:26:42.859  INFO 15306 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpTraceFilter' to: [/*]
2018-11-10 22:26:42.860  INFO 15306 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'webMvcMetricsFilter' to: [/*]
2018-11-10 22:26:43.503  INFO 15306 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@61b4a1b7: startup date [Sat Nov 10 22:26:38 CST 2018]; root of context hierarchy
2018-11-10 22:26:43.624  INFO 15306 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/sayhello.html]}" onto public java.lang.String com.bee.sample.ch1.controller.HelloworldController.say(java.lang.String)
2018-11-10 22:26:43.626  INFO 15306 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/usercredit/{id}]}" onto public java.lang.Integer com.bee.sample.ch1.rest.UserReditRestController.getCreditLevel(java.lang.String)
2018-11-10 22:26:43.633  INFO 15306 --- [  restartedMain] s.w.s.m.m.a.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)
2018-11-10 22:26:43.634  INFO 15306 --- [  restartedMain] s.w.s.m.m.a.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)
2018-11-10 22:26:43.715  INFO 15306 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-11-10 22:26:43.715  INFO 15306 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-11-10 22:26:43.792  INFO 15306 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-11-10 22:26:44.357  INFO 15306 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2018-11-10 22:26:44.395  INFO 15306 --- [  restartedMain] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped "{[/actuator/health],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.String>)
2018-11-10 22:26:44.396  INFO 15306 --- [  restartedMain] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped "{[/actuator/info],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.String>)
2018-11-10 22:26:44.397  INFO 15306 --- [  restartedMain] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped "{[/actuator],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto protected java.util.Map<java.lang.String, java.util.Map<java.lang.String, org.springframework.boot.actuate.endpoint.web.Link>> org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping.links(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-11-10 22:26:44.559  INFO 15306 --- [  restartedMain] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-11-10 22:26:44.624  INFO 15306 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2018-11-10 22:26:44.629  INFO 15306 --- [  restartedMain] com.bee.sample.ch1.Ch1Application        : Started Ch1Application in 6.572 seconds (JVM running for 7.23)
2018-11-10 22:26:51.227  INFO 15306 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2018-11-10 22:26:51.227  INFO 15306 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2018-11-10 22:26:51.266  INFO 15306 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 39 ms
args:[springboot]
return :hello springboot
args:[springboot]
return :hello springboot

aboycdog 2018年11月11日

解决了, 没想到是这个原因 https://stackoverflow.com/questions/36325529/spring-controller-method-called-twice

把插件禁掉就好了

闲大赋 2018年11月12日

没看懂,能够给点线索,书正好要第二版,看看能否注明这种意外情况?