zoukankan      html  css  js  c++  java
  • diamond 使用demo

    @Component
    public class DiamondDemo {

    /**
    * 这里null的数据,是通过application.properties配置注入的
    */
    private String stringValue;

    private int intValue;

    private boolean booleanValue;

    public String getStringValue() {
    return stringValue;
    }

    public int getIntValue() {
    return intValue;
    }

    public boolean getBooleanValue() {
    return booleanValue;
    }
    }

    @DiamondListener(dataId = "com.taobao.middleware:configFromListener.properties")
    public class DiamondDataCallbackDemo implements DiamondDataCallback {

    // @Autowired
    // private ConfigBean configBean;

    @Autowired
    private Environment environment;

    private String dataCahe;

    public String getReceivedData() {
    return dataCahe;
    }

    @Override
    public void received(String data) {
    try {
    dataCahe = data;
    Properties properties = new Properties();
    properties.load(new ByteArrayInputStream(data.getBytes()));
    System.out.println("received from diamond listener: " + properties);

    // 把properties的值注入到ConfigBean里

    // new org.springframework.boot.bind.RelaxedDataBinder(configBean)
    // .bind(new org.springframework.beans.MutablePropertyValues(properties));

    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }



    @RunWith(PandoraBootRunner.class)
    @DelegateTo(SpringJUnit4ClassRunner.class)
    @SpringBootTest(classes = { Application.class })
    public class DiamondTest {

    @Autowired
    DiamondDataCallbackDemo callback;

    @Autowired
    private DiamondDemo diamondDemo;

    @Test
    public void testGet() {
    TestCase.assertNotNull(diamondDemo.getStringValue());
    }

    @Test
    public void testListener() {
    // 增加listener后,需要等一会儿才能收到配置信息
    // TestCase.assertNotNull(callback.getReceivedData());
    }
    }
  • 相关阅读:
    典型用户与场景
    团队工作总结
    《构建之法》第8,9,10章
    冲刺1,2,3,4,5,天
    Github以及推广
    四则运算安卓版ver.mk3
    软件工程APP进度更新
    团队会议之事后工作总结
    构建之法 13-17章有感
    对于其他小组评论的反馈
  • 原文地址:https://www.cnblogs.com/wxmdevelop/p/14341174.html
Copyright © 2011-2022 走看看