• 大小: 6.8MB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2023-08-17
  • 语言: 其他
  • 标签: elastic  search  spring  mvc  

资源简介

spring spingmvc 集成elasticSearch 5.5.x版本 ,基本的增删改查.完成

资源截图

代码片段和文件信息

package com.atguigu.springmvc.entities;
import java.net.InetAddress;
import java.util.Properties;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
@Component
public class Client   implements FactoryBean InitializingBean DisposableBean  {
   
  
    private String clusterNodes;
    private String clusterName;
    private Boolean clientTransportSniff = true;
    private Boolean clientIgnoreClusterName = Boolean.FALSE;
    private String clientPingTimeout = “5s“;
    private String clientNodesSamplerInterval = “5s“;
    private TransportClient client;
    private Properties properties;
    static final String COLON = “:“;
    static final String COMMA = ““;

    @Override
    public void destroy() throws Exception {
        try {
           
            if (client != null) {
                client.close();
            }
        } catch (final Exception e) {
          
        }
    }

    @Override
    public TransportClient getobject() throws Exception {
        return client;
    }

    @Override
    public Class getobjectType() {
        return TransportClient.class;
    }

    @Override
    public boolean isSingleton() {
        return false;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        buildClient();
    }

    protected void buildClient() throws Exception {
        client = new PreBuiltTransportClient(settings()); 
           System.out.println(“连接开始“);
            String port =  “9300“;
         System.out.println();
            Assert.hasText(port “[Assertion failed] missing port in ‘clusterNodes‘“);
             
            client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(“localhost“) Integer.valueOf(port)));
      
        client.connectedNodes();
    }

    private Settings settings() {
        if (properties != null) {
            return Settings.builder().put(properties).build();
        }
        return Settings.builder()
                .put(“cluster.name“ clusterName)
                .put(“client.transport.sniff“ clientTransportSniff)
                .put(“client.transport.ignore_cluster_name“ clientIgnoreClusterName)
                .put(“client.transport.ping_timeout“ clientPingTimeout)
                .put(“client.transport.nodes_sampler_interval“ clientNodesSamplerInterval)
                .build();
    }

    public void

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       4483  2017-07-20 09:25  springmvc-1\.classpath

     文件       1428  2017-07-19 17:03  springmvc-1\.project

     文件        503  2014-12-07 09:33  springmvc-1\.settings\.jsdtscope

     文件         57  2017-07-20 09:24  springmvc-1\.settings\org.eclipse.core.resources.prefs

     文件        736  2017-07-20 09:25  springmvc-1\.settings\org.eclipse.jdt.core.prefs

     文件         90  2017-07-19 17:03  springmvc-1\.settings\org.eclipse.m2e.core.prefs

     文件        569  2017-07-20 09:21  springmvc-1\.settings\org.eclipse.wst.common.component

     文件        345  2014-12-07 09:33  springmvc-1\.settings\org.eclipse.wst.common.project.facet.core.xml

     文件         49  2014-12-07 09:33  springmvc-1\.settings\org.eclipse.wst.jsdt.ui.superType.container

     文件          6  2014-12-07 09:33  springmvc-1\.settings\org.eclipse.wst.jsdt.ui.superType.name

     文件         50  2017-07-20 09:21  springmvc-1\.settings\org.eclipse.wst.validation.prefs

     文件        453  2014-12-07 09:48  springmvc-1\.springBeans

     文件        508  2017-07-20 09:14  springmvc-1\build\classes\applicationContext.xml

     文件       1016  2017-07-20 09:12  springmvc-1\build\classes\com\atguigu\springmvc\entities\Address.class

     文件        338  2017-07-20 09:15  springmvc-1\build\classes\com\atguigu\springmvc\entities\ESTransportClient.class

     文件       2598  2017-07-20 09:12  springmvc-1\build\classes\com\atguigu\springmvc\entities\User.class

     文件        757  2017-07-20 09:12  springmvc-1\build\classes\com\atguigu\springmvc\handlers\HelloWorld.class

     文件       7596  2017-07-20 09:12  springmvc-1\build\classes\com\atguigu\springmvc\handlers\SpringMVCTest.class

     文件       1520  2017-07-20 09:12  springmvc-1\build\classes\com\atguigu\springmvc\views\HelloView.class

     文件         46  2014-12-13 20:53  springmvc-1\build\classes\i18n.properties

     文件         46  2014-12-13 20:53  springmvc-1\build\classes\i18n_en_US.properties

     文件         60  2014-12-13 20:54  springmvc-1\build\classes\i18n_zh_CN.properties

     文件       3643  2017-07-20 13:55  springmvc-1\pom.xml

     文件        619  2017-07-20 12:13  springmvc-1\src\applicationContext.xml

     文件       4794  2017-07-20 12:13  springmvc-1\src\com\atguigu\springmvc\entities\Client.java

     文件        470  2017-07-20 13:37  springmvc-1\src\com\atguigu\springmvc\entities\Student.java

     文件       3609  2017-07-20 17:21  springmvc-1\src\com\atguigu\springmvc\handlers\HelloWorld.java

     文件        949  2017-07-20 17:18  springmvc-1\src\com\atguigu\springmvc\service\ElSerarchService.java

     文件       6962  2017-07-20 17:25  springmvc-1\src\com\atguigu\springmvc\service\Impl\ElSerarchServiceImpl.java

     文件        626  2017-07-19 16:27  springmvc-1\src\com\atguigu\springmvc\views\HelloView.java

............此处省略83个文件信息

评论

共有 条评论