Ver código fonte

新增hibernate拦截和zuul拦截

chenweida 6 anos atrás
pai
commit
25374e79b5

+ 1 - 0
admin/admin-client-starter/src/main/resources/META-INF/spring.factories

@ -1,3 +1,4 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
  com.yihu.admin.client.config.WebsocketConfig,\
  com.yihu.admin.client.config.HibernateAutoConfig,\
  com.yihu.admin.client.config.ScheduledConfig

+ 43 - 32
admin/admin-server-starter/src/main/java/com/yihu/admin/server/config/AdminServerAutoConfig.java

@ -55,43 +55,54 @@ public class AdminServerAutoConfig {
    @PostConstruct
    public void createIndex() throws Exception {
        Client client = elastricSearchHelper.getElasticsearchUtil().getElasticFactory();
        try {
            Client client = elastricSearchHelper.getElasticsearchUtil().getElasticFactory();
            //判断index是否存在
            if (!client.prepareExists(adminServerProperties.getDefaultIndexName()).get().exists()) {
                CreateIndexRequestBuilder cib = client.admin()
                        .indices().prepareCreate(adminServerProperties.getDefaultIndexName());
                XContentBuilder mapping = XContentFactory.jsonBuilder()
                        .startObject()
                        .startObject("properties") //设置之定义字段
                        .startObject("uri")
                        .field("type", "string") //设置数据类型
                        .field("index", "not_analyzed") //设置数据类型	"index": "not_analyzed"
                        .endObject()
                        .startObject("spanname")
                        .field("type", "string")
                        .field("index", "not_analyzed") //设置数据类型	"index": "not_analyzed"
                        .endObject()
                        .startObject("ip")
                        .field("type", "string")
                        .field("index", "not_analyzed") //设置数据类型	"index": "not_analyzed"
                        .endObject()
                        .startObject("eventname")
                        .field("type", "string")
                        .field("index", "not_analyzed") //设置数据类型	"index": "not_analyzed"
                        .endObject()
                        .startObject("method")
                        .field("type", "string")
                        .field("index", "not_analyzed") //设置数据类型	"index": "not_analyzed"
                        .endObject()
                        .endObject()
                        .endObject();
                cib.addMapping(adminServerProperties.getDefaultTypeName(), mapping);
                CreateIndexResponse indexResponse = cib.execute().actionGet();
                logger.info("自动创建索引");
            Boolean flag = client.prepareExists(adminServerProperties.getDefaultIndexName()).get().exists();
            if (!flag) {
                createIndex(client);
            }
        } catch (org.elasticsearch.index.IndexNotFoundException e) {
            createIndex(client);
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
    }
    private void createIndex(Client client) {
        try {
            CreateIndexRequestBuilder cib = client.admin()
                    .indices().prepareCreate(adminServerProperties.getDefaultIndexName());
            XContentBuilder mapping = XContentFactory.jsonBuilder()
                    .startObject()
                    .startObject("properties") //设置之定义字段
                    .startObject("uri")
                    .field("type", "string") //设置数据类型
                    .field("index", "not_analyzed") //设置数据类型	"index": "not_analyzed"
                    .endObject()
                    .startObject("spanname")
                    .field("type", "string")
                    .field("index", "not_analyzed") //设置数据类型	"index": "not_analyzed"
                    .endObject()
                    .startObject("ip")
                    .field("type", "string")
                    .field("index", "not_analyzed") //设置数据类型	"index": "not_analyzed"
                    .endObject()
                    .startObject("eventname")
                    .field("type", "string")
                    .field("index", "not_analyzed") //设置数据类型	"index": "not_analyzed"
                    .endObject()
                    .startObject("method")
                    .field("type", "string")
                    .field("index", "not_analyzed") //设置数据类型	"index": "not_analyzed"
                    .endObject()
                    .endObject()
                    .endObject();
            cib.addMapping(adminServerProperties.getDefaultTypeName(), mapping);
            CreateIndexResponse indexResponse = cib.execute().actionGet();
            logger.info("自动创建索引");
        }catch (Exception e){
            logger.error(e.getMessage());
        }
    }
}