1616 */
1717package com .alipay .sofa .dashboard .client .config ;
1818
19- import com .alipay .sofa .dashboard .client .listener .ApplicationContextClosedListener ;
20- import com .alipay .sofa .dashboard .client .listener .ApplicationContextRefreshedListener ;
19+ import com .alipay .sofa .dashboard .client .listener .SofaDashboardClientApplicationContextClosedListener ;
20+ import com .alipay .sofa .dashboard .client .listener .SofaDashboardClientApplicationContextRefreshedListener ;
2121import com .alipay .sofa .dashboard .client .registration .SofaDashboardClientRegister ;
2222import com .alipay .sofa .dashboard .client .zookeeper .ZkCommandClient ;
2323import org .apache .curator .framework .CuratorFramework ;
2424import org .springframework .beans .factory .annotation .Autowired ;
2525import org .springframework .boot .autoconfigure .condition .ConditionalOnClass ;
2626import org .springframework .boot .autoconfigure .condition .ConditionalOnMissingBean ;
27+ import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
2728import org .springframework .boot .autoconfigure .condition .ConditionalOnWebApplication ;
2829import org .springframework .boot .context .properties .EnableConfigurationProperties ;
2930import org .springframework .context .annotation .Bean ;
30- import org .springframework .context .annotation .Conditional ;
3131import org .springframework .context .annotation .Configuration ;
3232import org .springframework .core .env .Environment ;
33+ import org .springframework .util .StringUtils ;
3334
3435/**
3536 * @author: guolei.sgl (guolei.sgl@antfin.com) 2019/2/15 2:03 PM
3839@ Configuration
3940@ EnableConfigurationProperties ({ SofaDashboardProperties .class })
4041@ ConditionalOnWebApplication
41- @ Conditional ( SofaDashboardClientEnabledCondition . class )
42+ @ ConditionalOnProperty ( prefix = "com.alipay.sofa.dashboard.client" , value = "enable" , matchIfMissing = true )
4243@ ConditionalOnClass (CuratorFramework .class )
4344public class SofaDashboardClientAutoConfiguration {
4445
@@ -47,8 +48,11 @@ public class SofaDashboardClientAutoConfiguration {
4748
4849 @ Bean
4950 @ ConditionalOnMissingBean
50- public SofaDashboardClientRegister registrator (SofaDashboardProperties sofaClientProperties ,
51- ZkCommandClient commandClient ) {
51+ public SofaDashboardClientRegister sofaDashboardClientRegister (SofaDashboardProperties sofaClientProperties ,
52+ ZkCommandClient commandClient ) {
53+ if (StringUtils .isEmpty (sofaClientProperties .getZookeeper ().getAddress ())) {
54+ throw new RuntimeException ("please config dashboard client zookeeper address." );
55+ }
5256 return new SofaDashboardClientRegister (sofaClientProperties , commandClient , environment );
5357 }
5458
@@ -60,13 +64,13 @@ public ZkCommandClient zkCommandClient() {
6064
6165 @ Bean
6266 @ ConditionalOnMissingBean
63- public ApplicationContextRefreshedListener applicationContextRefreshedListener () {
64- return new ApplicationContextRefreshedListener ();
67+ public SofaDashboardClientApplicationContextRefreshedListener sofaDashboardClientApplicationContextRefreshedListener () {
68+ return new SofaDashboardClientApplicationContextRefreshedListener ();
6569 }
6670
6771 @ Bean
6872 @ ConditionalOnMissingBean
69- public ApplicationContextClosedListener applicationContextClosedListener () {
70- return new ApplicationContextClosedListener ();
73+ public SofaDashboardClientApplicationContextClosedListener sofaDashboardClientApplicationContextClosedListener () {
74+ return new SofaDashboardClientApplicationContextClosedListener ();
7175 }
7276}
0 commit comments