annotations and elasticsearch

This commit is contained in:
manalejandro 2018-07-12 21:02:30 +02:00
parent 74231fcf33
commit b260838e0c
13 changed files with 140 additions and 1 deletions

View File

@ -10,7 +10,7 @@
<packaging>war</packaging> <packaging>war</packaging>
<name>arjion</name> <name>arjion</name>
<description>Demo project for Spring Boot</description> <description>Demo project of Apache Tika for Spring Boot</description>
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>

View File

@ -0,0 +1,64 @@
package com.manalejandro.arjion;
import java.net.InetAddress;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
@Configuration
@EnableElasticsearchRepositories(basePackages = "com.manalejandro.arjion.repositories")
public class ESConfig {
@Value("${elasticsearch.host}")
private String EsHost;
@Value("${elasticsearch.port}")
private int EsPort;
@Value("${elasticsearch.clustername}")
private String EsClusterName;
@Value("${elasticsearch.nodename}")
private String EsNodeName;
@Value("${arjion.indexName}")
private String indexName;
@Value("${arjion.documentType}")
private String documentType;
private TransportClient client;
@Bean
public Client client() throws Exception {
Settings esSettings = Settings.builder().put("cluster.name", EsClusterName).put("node.name", EsNodeName)
.build();
client = new PreBuiltTransportClient(esSettings);
return client.addTransportAddress(new TransportAddress(InetAddress.getByName(EsHost), EsPort));
}
@Bean
public ElasticsearchOperations elasticsearchTemplate() throws Exception {
return new ElasticsearchTemplate(client());
}
@Bean
public String indexName() {
return indexName;
}
@Bean
public String documentType() {
return documentType;
}
}

View File

@ -0,0 +1,12 @@
package com.manalejandro.arjion;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(ArjionApplication.class);
}
}

View File

@ -0,0 +1,8 @@
package com.manalejandro.arjion.controllers;
import org.springframework.stereotype.Controller;
@Controller
public class MainController {
}

View File

@ -0,0 +1,5 @@
package com.manalejandro.arjion.forms;
public class DocumentoForm {
}

View File

@ -0,0 +1,12 @@
package com.manalejandro.arjion.model;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Mapping;
import org.springframework.data.elasticsearch.annotations.Setting;
@Document(indexName = "#{@indexName}", type = "#{@documentType}")
@Setting(settingPath = "/elasticsearch/settings.json")
@Mapping(mappingPath = "/elasticsearch/mapping.json")
public class Documento {
}

View File

@ -0,0 +1,11 @@
package com.manalejandro.arjion.repositories;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
import com.manalejandro.arjion.model.Documento;
@Repository
public interface MainRepository extends ElasticsearchRepository<Documento, String> {
}

View File

@ -0,0 +1,8 @@
package com.manalejandro.arjion.services;
import org.springframework.stereotype.Service;
@Service
public interface MainService {
}

View File

@ -0,0 +1,5 @@
package com.manalejandro.arjion.services;
public class MainServiceImpl implements MainService {
}

View File

@ -0,0 +1,5 @@
package com.manalejandro.arjion.vo;
public class DocumentoVO {
}

View File

@ -0,0 +1,9 @@
server.servlet.context-path=/arjion
server.port=8080
elasticsearch.clustername=development
elasticsearch.host=localhost
elasticsearch.port=9300
elasticsearch.nodename=arjion
arjion.indexName=documentos
arjion.documentType=documento
spring.main.allow-bean-definition-overriding=true