-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathissue-conditiontrack.html
1033 lines (551 loc) · 40.4 KB
/
issue-conditiontrack.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head hexo-theme='https://volantis.js.org/#2.6.5'>
<meta charset="utf-8">
<!-- SEO相关 -->
<!-- 渲染优化 -->
<meta name="renderer" content="webkit">
<meta name="force-rendering" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<meta name="HandheldFriendly" content="True" >
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<!-- 页面元数据 -->
<title>案例解析:springboot自动配置未生效问题定位(条件断点) - 半路雨歌</title>
<meta name="keywords" content="java">
<meta name="description" content="Spring Boot在为开发人员提供更高层次的封装,进而提高开发效率的同时,也为出现问题时如何进行定位带来了一定复杂性与难度。但Spring Boot同时又提供了一些诊断工具来辅助开发与分析,如spring-boot-starter-actuator。本文分享一个基于actuator与IDEA条件断点来定位自动...">
<!-- feed -->
<link rel="alternate" href="/atom.xml" title="半路雨歌">
<!-- import meta -->
<!-- link -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/css/all.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/[email protected]/dist/jquery.fancybox.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/waves.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/APlayer.min.css">
<!-- import link -->
<link rel="stylesheet" href="/css/style.css">
<script>
function setLoadingBarProgress(num) {
document.getElementById('loading-bar').style.width=num+"%";
}
</script>
<script data-ad-client="ca-pub-3748140524379452" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
</head>
<body>
<div id="loading-bar-wrapper">
<div id="loading-bar"></div>
</div>
<header class="l_header shadow blur">
<div class='container'>
<div class='wrapper'>
<div class='nav-sub'>
<p class="title"></p>
<ul class='switcher nav-list-h'>
<li><a class="s-comment fas fa-comments fa-fw" target="_self" href='javascript:void(0)'></a></li>
<li><a class="s-toc fas fa-list fa-fw" target="_self" href='javascript:void(0)'></a></li>
</ul>
</div>
<div class="nav-main">
<a class="title flat-box" target="_self" href='/'>
半路雨歌
</a>
<div class='menu navigation'>
<ul class='nav-list-h'>
<li>
<a class="flat-box" href=/
id="home"
>
<i class='fas fa-rss fa-fw'></i>首页
</a>
</li>
<li>
<a class="flat-box" href=/archives/
id="archives"
>
<i class='fas fa-archive fa-fw'></i>归档
</a>
</li>
<li>
<a class="flat-box" href=/friends/
id="friends"
>
<i class='fas fa-link fa-fw'></i>友链
</a>
</li>
<li>
<a class="flat-box" href=/about/
id="about"
>
<i class='fas fa-info-circle fa-fw'></i>关于
</a>
</li>
</ul>
</div>
<div class="m_search">
<form name="searchform" class="form u-search-form">
<i class="icon fas fa-search fa-fw"></i>
<input type="text" class="input u-search-input" placeholder="Search..." />
</form>
</div>
<ul class='switcher nav-list-h'>
<li><a class="s-search fas fa-search fa-fw" target="_self" href='javascript:void(0)'></a></li>
<li>
<a class="s-menu fas fa-bars fa-fw" target="_self" href='javascript:void(0)'></a>
<ul class="menu-phone list-v navigation white-box">
<li>
<a class="flat-box" href=/
id="home"
>
<i class='fas fa-rss fa-fw'></i>首页
</a>
</li>
<li>
<a class="flat-box" href=/archives/
id="archives"
>
<i class='fas fa-archive fa-fw'></i>归档
</a>
</li>
<li>
<a class="flat-box" href=/friends/
id="friends"
>
<i class='fas fa-link fa-fw'></i>友链
</a>
</li>
<li>
<a class="flat-box" href=/about/
id="about"
>
<i class='fas fa-info-circle fa-fw'></i>关于
</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</header>
<script>setLoadingBarProgress(40);</script>
<div class="l_body nocover">
<div class='body-wrapper'>
<div class='l_main'>
<article id="post" class="post white-box reveal shadow article-type-post" itemscope itemprop="blogPost">
<section class='meta'>
<div class="meta" id="header-meta">
<h1 class="title">
<a href="/issue-conditiontrack.html">
案例解析:springboot自动配置未生效问题定位(条件断点)
</a>
</h1>
<div class='new-meta-box'>
<div class="new-meta-item date">
<a class='notlink'>
<i class="fas fa-calendar-alt fa-fw" aria-hidden="true"></i>
<p>2019-06-25</p>
</a>
</div>
<div class='new-meta-item category'>
<a href='/categories/Java/' rel="nofollow">
<i class="fas fa-folder-open fa-fw" aria-hidden="true"></i>
<p>Java</p>
</a>
</div>
</div>
<hr>
</div>
</section>
<section class="article typo">
<div class="article-entry" itemprop="articleBody">
<p>Spring Boot在为开发人员提供更高层次的封装,进而提高开发效率的同时,也为出现问题时如何进行定位带来了一定复杂性与难度。但Spring Boot同时又提供了一些诊断工具来辅助开发与分析,如spring-boot-starter-actuator。本文分享一个基于actuator与IDEA条件断点来定位自动配置未生效的案例。望对类似问题分析与处理提供参考。</p>
<a id="more"></a>
<h3 id="问题确认"><a href="#问题确认" class="headerlink" title="问题确认"></a>问题确认</h3><p>在前文介绍的 <a href="/springboot-tkmapper.html">Spring Boot从入门到实战:整合通用Mapper简化单表操作</a> 中,我们对druid连接池做了自动配置,并且注入了druid的监控统计功能,如下</p>
<p><img src="/assets/statviewservlet.png" alt="druidstat"></p>
<p>但本地运行后通过 <a href="http://localhost:8080/druid/index.html" target="_blank" rel="noopener">http://localhost:8080/druid/index.html</a> 访问时却出现错误,通过浏览器的开发者工具查看该请求返回404,推测上述代码中定义的<code>StatViewServlet</code>未注入成功。我们用actuator来确认下是否如此。在项目中加入spring-boot-starter-actuator,并且application.yml中添加如下配置</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">management:</span></span><br><span class="line"> <span class="attr">endpoints:</span></span><br><span class="line"> <span class="attr">web:</span></span><br><span class="line"> <span class="attr">exposure:</span></span><br><span class="line"> <span class="attr">include:</span> <span class="string">"*"</span></span><br><span class="line"> <span class="attr">exclude:</span> <span class="string">beans,trace</span></span><br><span class="line"> <span class="attr">endpoint:</span></span><br><span class="line"> <span class="attr">health:</span></span><br><span class="line"> <span class="attr">show-details:</span> <span class="string">always</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p>在spring-boot 2.x 版本当中,作为安全性考虑,将actuator 控件中的端口,只默认开放/health 和/info 两个端口,其他端口默认关闭, 因此需要添加如上配置。注意include的值 <code>*</code> 必须加引号,否则无法启动。</p>
</blockquote>
<p>重启程序后访问 <a href="http://localhost:8080/actuator/conditions" target="_blank" rel="noopener">http://localhost:8080/actuator/conditions</a> 确认上述两个实例化方法未满足<code>@ConditionalOnProperty</code>的条件,从而未执行生效,如图</p>
<p><img src="/assets/actuatorconditions.png" alt="actuator"></p>
<h3 id="条件断点"><a href="#条件断点" class="headerlink" title="条件断点"></a>条件断点</h3><p>从上面分析确认是因为条件注解 <code>@ConditionalOnProperty(prefix = "spring.datasource.druid", name = "druidServletSettings")</code> 未满足使方法未执行导致。那这个条件为什么没有满足呢,查看application.yml中也做了 spring.datasource.druid.druidServletSettings属性的配置。</p>
<p>当你无法理清头绪,确定问题原因时,那就Debug吧。查看注解<code>@ConditionalOnProperty</code>源码,找到其实现支持类<code>OnPropertyCondition</code>,如下</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Retention</span>(RetentionPolicy.RUNTIME)</span><br><span class="line"><span class="meta">@Target</span>({ElementType.TYPE, ElementType.METHOD})</span><br><span class="line"><span class="meta">@Documented</span></span><br><span class="line"><span class="meta">@Conditional</span>({OnPropertyCondition<span class="class">.<span class="keyword">class</span>})</span></span><br><span class="line"><span class="class"><span class="title">public</span> @<span class="title">interface</span> <span class="title">ConditionalOnProperty</span> </span>{</span><br><span class="line"> String[] value() <span class="keyword">default</span> {};</span><br><span class="line"></span><br><span class="line"> <span class="function">String <span class="title">prefix</span><span class="params">()</span> <span class="keyword">default</span> ""</span>;</span><br><span class="line"></span><br><span class="line"> String[] name() <span class="keyword">default</span> {};</span><br><span class="line"></span><br><span class="line"> <span class="function">String <span class="title">havingValue</span><span class="params">()</span> <span class="keyword">default</span> ""</span>;</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">boolean</span> <span class="title">matchIfMissing</span><span class="params">()</span> <span class="keyword">default</span> <span class="keyword">false</span></span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p>查看<code>OnPropertyCondition</code>源码,了解它是通过<code>getMatchOutcome</code>方法来判断是否满足注解参数所指定的条件的,如下所示</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> ConditionOutcome <span class="title">getMatchOutcome</span><span class="params">(ConditionContext context,</span></span></span><br><span class="line"><span class="function"><span class="params"> AnnotatedTypeMetadata metadata)</span> </span>{</span><br><span class="line"> List<AnnotationAttributes> allAnnotationAttributes = annotationAttributesFromMultiValueMap(</span><br><span class="line"> metadata.getAllAnnotationAttributes(</span><br><span class="line"> ConditionalOnProperty<span class="class">.<span class="keyword">class</span>.<span class="title">getName</span>()))</span>;</span><br><span class="line"> List<ConditionMessage> noMatch = <span class="keyword">new</span> ArrayList<>();</span><br><span class="line"> List<ConditionMessage> match = <span class="keyword">new</span> ArrayList<>();</span><br><span class="line"> <span class="keyword">for</span> (AnnotationAttributes annotationAttributes : allAnnotationAttributes) {</span><br><span class="line"> ConditionOutcome outcome = determineOutcome(annotationAttributes,</span><br><span class="line"> context.getEnvironment());</span><br><span class="line"> (outcome.isMatch() ? match : noMatch).add(outcome.getConditionMessage());</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (!noMatch.isEmpty()) {</span><br><span class="line"> <span class="keyword">return</span> ConditionOutcome.noMatch(ConditionMessage.of(noMatch));</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> ConditionOutcome.match(ConditionMessage.of(match));</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p>在调用<code>determineOutcome</code>处打断点,调试什么原因导致条件未满足,但是这里是一个for循环,如果for元素过多的话,将可能需要断点阻断很多次才能找到你想要查看的那个元素。所幸IDEA提供了不同类型的断点来处理这类问题,前面 <a href="/issue-errortrack.html">案例解析:使用IDEA异常断点来定位java.lang.ArrayStoreException的问题</a> 我们介绍了异常断点的使用。这里介绍用条件断点来处理这类循环块中的debug问题。</p>
<p>在上述代码for循环中调用<code>determineOutcome</code>行打断点,并在断点上右键,弹出如下窗口</p>
<p><img src="/assets/conditionbreak.png" alt="条件断点"></p>
<p>图中Condition框即可输入你要指定的条件,可以直接写java判断表达式代码,并引用该行代码处能访问的变量,如这里我们输入 <code>annotationAttributes.get("name").equals("druidServletSettings")</code>,然后点击Debug窗口的“Resume Program (F9)”按钮,则在不满足指定条件时,断点处将不会被阻断,直到条件满足,这样就能很容易定位到我们想要查看的元素。(当然这里<code>allAnnotationAttributes</code>变量其实只有一个元素,仅仅是为了演示条件变量的使用,当集合元素很多时,使用条件断点就能体会到它的方便之处)</p>
<h3 id="问题定位"><a href="#问题定位" class="headerlink" title="问题定位"></a>问题定位</h3><p>通过Debug的方式深入条件注解的判断逻辑(其中循环处可使用条件断点),最终来到如下代码片段</p>
<p><img src="/assets/conditonbreak3.png" alt="判断条件"></p>
<p>在这里是判断来自所有属性源配置的属性中,是否包含条件注解指定的属性,即<code>spring.datasource.druid.druidServletSettings</code>,由上图可见,<code>spring.datasource.druid.druidServletSettings</code>只是某些属性的前缀,并不存在完全匹配的属性,因此返回false,导致条件不满足。回看注解@ConditionOnProperty的javadoc,</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">* If the property is not contained in the {@link Environment} at all, the</span><br><span class="line"> * {@link #matchIfMissing()} attribute is consulted. By default missing attributes do not</span><br><span class="line"> * match.</span><br><span class="line"> * <p></span><br><span class="line"> * This condition cannot be reliably used for matching collection properties. For example,</span><br><span class="line"> * in the following configuration, the condition matches if {@code spring.example.values}</span><br><span class="line"> * is present in the {@link Environment} but does not match if</span><br><span class="line"> * {@code spring.example.values[0]} is present.</span><br><span class="line"> *</span><br></pre></td></tr></table></figure>
<p>当Environment中不包含该属性时,则看matchIfMissing的值,该值默认为false,如果包含该属性,则再对比属性值与havingValue的值,相等即满足,不等则不满足。并且该条件注解不能用于匹配集合类型属性。上述<code>spring.datasource.druid.druidServletSettings</code>实际上属于一个Map类型,因此不能想当然地认为该注解是只要属性集中某属性名称包含该值即满足。</p>
<h3 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h3><p>当难以定位到问题原因时,可以进行Debug,跟踪程序运行的各个步骤,当要在循环中Debug定位到某个元素时,可以用条件断点来实现。@ConditionalOnProperty注解不是存在某属性就行,还需要值相等,并且不适用于集合类型属性。<br></br><br></br><br>我的个人博客地址:<a href="http://blog.jboost.cn">http://blog.jboost.cn</a><br>我的头条空间: <a href="https://www.toutiao.com/c/user/5833678517/#mid=1636101215791112" target="_blank" rel="noopener">https://www.toutiao.com/c/user/5833678517/#mid=1636101215791112</a><br>我的github地址:<a href="https://github.com/ronwxy" target="_blank" rel="noopener">https://github.com/ronwxy</a><br>我的微信公众号:jboost-ksxy</p>
<p>———————————————————————————————————————————————————————————————</p>
<p><img src="/assets/qrcode-05.jpg" alt="微信公众号"><br>欢迎关注我的微信公众号,及时获取最新分享</p>
<div class='article_footer'>
<section class="widget copyright desktop mobile">
<div class='content'>
<blockquote>
<p>作者:雨歌</p>
<p>本文版权归作者所有,转载请明确注明出处</p>
<p>本文链接:<a href=http://blog.jboost.cn/issue-conditiontrack.html>http://blog.jboost.cn/issue-conditiontrack.html</a></p>
<p>如果觉得本文对你有帮助,请扫描下方二维码,关注作者公众号,感谢支持!</p>
</blockquote>
</div>
</section>
<section class="widget qrcode desktop mobile">
<header>
<i class="fab fa-weixin fa-fw" aria-hidden="true"></i><span class='name'>关注作者</span>
</header>
<div class='content article-entry'>
<div class='fancybox'><img src='/assets/qrcode-05.jpg'
height='200px'
></div>
</div>
</section>
</div>
</div>
<section class='meta' id="footer-meta">
<div class='new-meta-box'>
<div class="new-meta-item date" itemprop="dateUpdated" datetime="2020-08-26T09:39:29+08:00">
<a class='notlink'>
<i class="fas fa-edit fa-fw" aria-hidden="true"></i>
<p>更新于:2020-08-26</p>
</a>
</div>
<div class="new-meta-item meta-tags"><a class="tag" href="/tags/java/" rel="nofollow"><i class="fas fa-hashtag fa-fw" aria-hidden="true"></i><p>java</p></a></div>
<div class="new-meta-item share -mob-share-list">
<div class="-mob-share-list share-body">
<a class="-mob-share-qq" title="" rel="external nofollow noopener noreferrer"
href="http://connect.qq.com/widget/shareqq/index.html?url=http://blog.jboost.cn/issue-conditiontrack.html&title=案例解析:springboot自动配置未生效问题定位(条件断点) - 半路雨歌&summary=Spring Boot在为开发人员提供更高层次的封装,进而提高开发效率的同时,也为出现问题时如何进行定位带来了一定复杂性与难度。但Spring Boot同时又提供了一些诊断工具来辅助开发与分析,如spring-boot-starter-actuator。本文分享一个基于actuator与IDEA条件断点来定位自动配置未生效的案例。望对类似问题分析与处理提供参考。"
>
<img src="https://cdn.jsdelivr.net/gh/xaoxuu/cdn-assets/logo/128/qq.png">
</a>
<a class="-mob-share-qzone" title="" rel="external nofollow noopener noreferrer"
href="https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=http://blog.jboost.cn/issue-conditiontrack.html&title=案例解析:springboot自动配置未生效问题定位(条件断点) - 半路雨歌&summary=Spring Boot在为开发人员提供更高层次的封装,进而提高开发效率的同时,也为出现问题时如何进行定位带来了一定复杂性与难度。但Spring Boot同时又提供了一些诊断工具来辅助开发与分析,如spring-boot-starter-actuator。本文分享一个基于actuator与IDEA条件断点来定位自动配置未生效的案例。望对类似问题分析与处理提供参考。"
>
<img src="https://cdn.jsdelivr.net/gh/xaoxuu/cdn-assets/logo/128/qzone.png">
</a>
<a class="-mob-share-weibo" title="" rel="external nofollow noopener noreferrer"
href="http://service.weibo.com/share/share.php?url=http://blog.jboost.cn/issue-conditiontrack.html&title=案例解析:springboot自动配置未生效问题定位(条件断点) - 半路雨歌&summary=Spring Boot在为开发人员提供更高层次的封装,进而提高开发效率的同时,也为出现问题时如何进行定位带来了一定复杂性与难度。但Spring Boot同时又提供了一些诊断工具来辅助开发与分析,如spring-boot-starter-actuator。本文分享一个基于actuator与IDEA条件断点来定位自动配置未生效的案例。望对类似问题分析与处理提供参考。"
>
<img src="https://cdn.jsdelivr.net/gh/xaoxuu/cdn-assets/logo/128/weibo.png">
</a>
<div class='hoverbox'>
<a><img src="https://cdn.jsdelivr.net/gh/xaoxuu/cdn-assets/logo/128/wechat.png"></a>
<div class='target'>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAARgAAAEYCAAAAACi5bZQAAAC/0lEQVR42u3aQXLjMAwEQP//05sPrEvEAHKEuHVzIlFE6zIF8PXP9d/rhQAMGDBgwIBZA/MKr7cLX/z/6v5377n6PVUPGDBgwIABA2YfTFpItaC7729/GDBgwIABAwbMWpjLAHT4u1r4aVBLoY7vBwMGDBgwYMB8LczVxqeeO10XDBgwYMCAAQPm04OvbkMLDBgwYMCAAfN9MN2DPtPBLN3Pr08iwYABAwYMGDAfg0mD2FN/x/WAAQMGDBgwYNbAdK/pwtLgOFYPGDBgwIABA2YNTBqQug2ttOF0GjjT/YMBAwYMGDBg9sHcfbCne8DoNNil7wEDBgwYMGDA/B2Y9GBOdwCWBrqxoAkGDBgwYMCAWQ9z+sLqQZ402KXBr/whwIABAwYMGDBrYKYKqILcFRhP63q7PhgwYMCAAQNmDUx1Y+nALA2C1X2ND9zAgAEDBgwYMI+H6Tacuo2q6npTQMcdPDBgwIABAwbM42CqA63T4Fcd1FWfmwYBAwYMGDBgwOyDSRtK6fPp4K3ccAo/MBgwYMCAAQNmL8zxAmFhU0EwbYBd1gEGDBgwYMCAWQtzunA1yKUHiqYaXO1JJBgwYMCAAQPmcTDVgVW6gVOYqQZaPEgEAwYMGDBgwKyBqR7EqQ7GuoV0g195PTBgwIABAwbMepgqSPfAURo4u4O/8iQSDBgwYMCAAfM4mLTgauHdhlJ3sFeeRIIBAwYMGDBg1sGkB4lO758u9OrDHu8TDBgwYMCAAbMepjs4mzp4dFuQAwMGDBgwYMCsh+leadDqBr/bBoFgwIABAwYMmDUwU4GpfEAnXPe0IVYdBIIBAwYMGDBg9sJ0C7x7UNcNlnHAAwMGDBgwYMCsgekGqHRA1g10YweZwIABAwYMGDBfB1NuCDX/3g2aHwt4YMCAAQMGDJg1MGmjKX2+ekDpshEHBgwYMGDAgFkLUx24pRtO33tcYNoYAwMGDBgwYMCsg+kOrqqNq7iR1Nzv5QcEAwYMGDBgwKyBcYEBAwYMGDBgll0/vpLn4fezdbUAAAAASUVORK5CYII=">
</div>
</div>
</div>
</div>
</div>
</section>
<div class="prev-next">
<a class='prev' href='/springboot-aoplog.html'>
<p class='title'><i class="fas fa-chevron-left" aria-hidden="true"></i>Spring Boot从入门到实战(八):集成AOPLog来记录接口访问日志</p>
<p class='content'>日志是一个Web项目中必不可少的部分,借助它我们可以做许多事情,比如问题排查、访问统计、监控告警等。一般通过引入slf4j的一些实现框架来做日志功能,如log4j,logback,log4j2,...</p>
</a>
<a class='next' href='/springboot-tkmapper.html'>
<p class='title'>Spring Boot从入门到实战(七):整合通用Mapper简化单表操作<i class="fas fa-chevron-right" aria-hidden="true"></i></p>
<p class='content'>数据库访问是web应用必不可少的部分。现今最常用的数据库ORM框架有Hibernate与Mybatis,Hibernate貌似在传统IT企业用的较多,而Mybatis则在互联网企业应用较多。通用...</p>
</a>
</div>
</section>
</article>
<!-- 显示推荐文章和评论 -->
<article class="post white-box reveal comments shadow">
<section class="article typo">
<p ct><i class='fas fa-comments'></i> 评论</p>
<section id="comments">
<div id="valine_container" class="valine_thread">
<i class="fas fa-cog fa-spin fa-fw fa-2x"></i>
</div>
</section>
</section>
</article>
<!-- 根据页面mathjax变量决定是否加载MathJax数学公式js -->
<script>
window.subData = {
title: '案例解析:springboot自动配置未生效问题定位(条件断点)',
tools: true
}
</script>
</div>
<aside class='l_side'>
<section class="widget qrcode shadow desktop mobile">
<header>
<i class="fab fa-weixin fa-fw" aria-hidden="true"></i><span class='name'>关注作者</span>
</header>
<div class='content article-entry'>
<div class='fancybox'><img src='/assets/qrcode-05.jpg'
height='200px'
></div>
</div>
</section>
<section class="widget toc-wrapper shadow desktop mobile">
<header>
<i class="fas fa-list fa-fw" aria-hidden="true"></i><span class='name'>本文目录</span>
</header>
<div class='content'>
<ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#问题确认"><span class="toc-text">问题确认</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#条件断点"><span class="toc-text">条件断点</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#问题定位"><span class="toc-text">问题定位</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#总结"><span class="toc-text">总结</span></a></li></ol>
</div>
</section>
</aside>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
<footer class="clearfix">
<br><br>
<br>
<div class="social-wrapper">
<a href="/assets/qrcode-05.jpg"
class="social fab fa-weixin flat-btn"
target="_blank"
rel="external nofollow noopener noreferrer">
</a>
<a href="mailto:[email protected]"
class="social fas fa-envelope flat-btn"
target="_blank"
rel="external nofollow noopener noreferrer">
</a>
<a href="https://github.com/ronwxy"
class="social fab fa-github flat-btn"
target="_blank"
rel="external nofollow noopener noreferrer">
</a>
</div>
<div><p>Blog content follows the <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.en" target="_blank" rel="noopener">Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) License</a></p>
</div>
Use
<a href="https://volantis.js.org/" target="_blank" class="codename">Volantis</a>
as theme<span id="busuanzi_container_site_pv" style='display:none'>, total visits
<span id="busuanzi_value_site_pv"><i class="fas fa-circle-notch fa-spin fa-fw" aria-hidden="true"></i></span>
times</span>
<span id="busuanzi_container_site_uv" style='display:none'>
, total visitors
<span id="busuanzi_value_site_uv"><i class="fas fa-circle-notch fa-spin fa-fw" aria-hidden="true"></i></span>
times</span>
<div class='copyright'>
<p>Copyright@2019-2020 半路雨歌</p>
</div>
</footer>
<script>
setLoadingBarProgress(80);
$(document).ready(function() {
var int = setInterval(fixCount, 50); // 50ms周期检测函数
var pvOffset = 25000; // 初始化首次数据
var uvOffset = 12000;
function fixCount() {
if (document.getElementById("busuanzi_container_site_pv").style.display != "none")
{
$("#busuanzi_value_site_pv").html(parseInt($("#busuanzi_value_site_pv").html()) + pvOffset);
clearInterval(int);
}
if ($("#busuanzi_container_site_uv").css("display") != "none")
{
$("#busuanzi_value_site_uv").html(parseInt($("#busuanzi_value_site_uv").html()) + uvOffset); // 加上初始数据
clearInterval(int); // 停止检测
}
}
});
</script>
<script>setLoadingBarProgress(60);</script>
</div>
<a class="s-top fas fa-arrow-up fa-fw" href='javascript:void(0)'></a>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
<script>
var SEARCH_SERVICE = "hexo" || "hexo";
var ROOT = "/" || "/";
if (!ROOT.endsWith('/')) ROOT += '/';
</script>
<script async src="https://cdn.jsdelivr.net/gh/xaoxuu/cdn-volantis@2/js/instant_page.js" type="module" defer integrity="sha384-OeDn4XE77tdHo8pGtE1apMPmAipjoxUQ++eeJa6EtJCfHlvijigWiJpD7VDPWXV1"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/scrollreveal.min.js"></script>
<script type="text/javascript">
$(function() {
ScrollReveal().reveal('.l_main .reveal', {
distance: '8px',
duration: '800',
interval: '100',
scale: '1'
});
});
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/waves.min.js"></script>
<script type="text/javascript">
$(function() {
Waves.attach('.flat-btn', ['waves-button']);
Waves.attach('.float-btn', ['waves-button', 'waves-float']);
Waves.attach('.float-btn-light', ['waves-button', 'waves-float', 'waves-light']);
Waves.attach('.flat-box', ['waves-block']);
Waves.attach('.float-box', ['waves-block', 'waves-float']);
Waves.attach('.waves-image');
Waves.init();
});
</script>
<script async src="https://cdn.jsdelivr.net/gh/xaoxuu/[email protected]/js/busuanzi.pure.mini.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/jquery.backstretch.min.js"></script>
<script type="text/javascript">
$(function(){
var imgs=["assets/sea01.jpg", "https://cdn.jsdelivr.net/gh/xaoxuu/cdn-wallpaper/abstract/41F215B9-261F-48B4-80B5-4E86E165259E.jpeg", "https://cdn.jsdelivr.net/gh/xaoxuu/cdn-wallpaper/abstract/67239FBB-E15D-4F4F-8EE8-0F1C9F3C4E7C.jpeg", "https://cdn.jsdelivr.net/gh/xaoxuu/cdn-wallpaper/abstract/BBC19066-E176-47C2-9D22-48C81EE5DF6B.jpeg", "https://cdn.jsdelivr.net/gh/xaoxuu/cdn-wallpaper/abstract/B18FCBB3-67FD-48CC-B4F3-457BA145F17A.jpeg", "https://cdn.jsdelivr.net/gh/xaoxuu/cdn-wallpaper/abstract/00E0F0ED-9F1C-407A-9AA6-545649D919F4.jpeg", "https://cdn.jsdelivr.net/gh/xaoxuu/cdn-wallpaper/abstract/2884F904-F1F3-479E-AE27-5EBC291B63B0.jpeg"];
if ('true' == 'true') {
function shuffle(arr){
/*From countercurrent-time*/
var n = arr.length;
while(n--) {
var index = Math.floor(Math.random() * n);
var temp = arr[index];
arr[index] = arr[n];
arr[n] = temp;
}
}
shuffle(imgs);
}
if ('') {
$('').backstretch(
imgs,
{
duration: "30000",
fade: "1500"
});
} else {
$.backstretch(
imgs,
{
duration: "30000",
fade: "1500"
});
}
});
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/APlayer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/Meting.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/Valine.min.js"></script>
<script>
var GUEST_INFO = ['nick','mail','link'];
var meta = 'nick,mail,link'.split(',').filter(function(item){
return GUEST_INFO.indexOf(item) > -1
});
var REQUIRED_FIELDS = ['nick','mail','link'];
var requiredFields = 'nick,mail'.split(',').filter(function(item){
return REQUIRED_FIELDS.indexOf(item) > -1
});
var valine = new Valine();
function emoji(path, idx, ext) {
return path + "/" + path + "-" + idx + "." + ext;
}
var emojiMaps = {};
for (var i = 1; i <= 54; i++) {
emojiMaps['tieba-' + i] = emoji('tieba', i, 'png');
}
for (var i = 1; i <= 101; i++) {
emojiMaps['qq-' + i] = emoji('qq', i, 'gif');
}
for (var i = 1; i <= 116; i++) {
emojiMaps['aru-' + i] = emoji('aru', i, 'gif');
}
for (var i = 1; i <= 125; i++) {
emojiMaps['twemoji-' + i] = emoji('twemoji', i, 'png');
}
for (var i = 1; i <= 4; i++) {
emojiMaps['weibo-' + i] = emoji('weibo', i, 'png');
}
valine.init({
el: '#valine_container',
meta: meta,
appId: "g1Ew6IgbqodabnGjq0nDI39n-gzGzoHsz",
appKey: "PhFNiYoBJ1Fge6n8stpsfggG",
placeholder: "快来评论吧~",
pageSize:'10',
avatar:'robohash',
lang:'zh-cn',
visitor: 'true',
highlight: 'true',
mathJax: 'false',
enableQQ: 'true',
requiredFields: requiredFields,
emojiCDN: 'https://cdn.jsdelivr.net/gh/xaoxuu/cdn-assets/emoji/valine/',
emojiMaps: emojiMaps
})
</script>
<script src="/js/app.js"></script>
<script src="https://cdn.jsdelivr.net/gh/xaoxuu/[email protected]/js/search.js"></script>
<script src="https://cdn.jsdelivr.net/gh/xaoxuu/cdn-volantis@2/js/comment_typing.js"></script>
<!-- 复制 -->
<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
function wait(callback, seconds) {
var timelag = null;
timelag = window.setTimeout(callback, seconds);
}
!function (e, t, a) {
var initCopyCode = function(){
var copyHtml = '';
copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
copyHtml += '<i class="fas fa-copy"></i><span>COPY</span>';
copyHtml += '</button>';
$(".highlight .code pre").before(copyHtml);
$(".article pre code").before(copyHtml);
var clipboard = new ClipboardJS('.btn-copy', {
target: function(trigger) {
return trigger.nextElementSibling;
}
});
clipboard.on('success', function(e) {
let $btn = $(e.trigger);
$btn.addClass('copied');
let $icon = $($btn.find('i'));
$icon.removeClass('fa-copy');
$icon.addClass('fa-check-circle');
let $span = $($btn.find('span'));
$span[0].innerText = 'COPIED';
wait(function () { // 等待两秒钟后恢复
$icon.removeClass('fa-check-circle');
$icon.addClass('fa-copy');
$span[0].innerText = 'COPY';
}, 2000);
});
clipboard.on('error', function(e) {
e.clearSelection();
let $btn = $(e.trigger);
$btn.addClass('copy-failed');
let $icon = $($btn.find('i'));
$icon.removeClass('fa-copy');
$icon.addClass('fa-times-circle');
let $span = $($btn.find('span'));
$span[0].innerText = 'COPY FAILED';
wait(function () { // 等待两秒钟后恢复
$icon.removeClass('fa-times-circle');
$icon.addClass('fa-copy');
$span[0].innerText = 'COPY';
}, 2000);
});
}
initCopyCode();
}(window, document);
</script>