spring - 在 Jhipster 中设置 bonsai-elasticsearch - Heroku

标签 spring heroku elasticsearch jhipster bonsai-elasticsearch

在将我的 Jhipster 应用程序部署到 heroku 之后,我想将云 Elasticsearch (盆景)与 JHipster 一起使用。 Bonsai 提供以下环境变量:

$BONSAI_URL 

如何将其正确添加到 application-prod.yml 中? 我一直在阅读文档并尝试将其设置为集群节点值和主机。但我有点迷路了。任何提示都非常受欢迎。

application-prod.yml

spring:
devtools:
    restart:
        enabled: false
    livereload:
        enabled: false
datasource:
    url: jdbc:mysql://localhost:3306/App?useUnicode=true&characterEncoding=utf8&useSSL=false
    name:
    username: root
    password:
    hikari:
        data-source-properties:
            cachePrepStmts: true
            prepStmtCacheSize: 250
            prepStmtCacheSqlLimit: 2048
            useServerPrepStmts: true
jpa:
    database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
    database: MYSQL
    show_sql: false
    properties:
        hibernate.cache.use_second_level_cache: true
        hibernate.cache.use_query_cache: false
        hibernate.generate_statistics: false
        hibernate.cache.region.factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
data:
    elasticsearch:
        network:
            host: ${BONSAI_URL}
        cluster-name:  VLT
        cluster-nodes: localhost:9300
mail:
    host: smtp.sendgrid.net
    port: 587
    username: ${SENDGRID_USERNAME}
    password: ${SENDGRID_PASSWORD}
    protocol: smtp
    tls: false
    auth: true
    from: noreply@app.com

thymeleaf:
    cache: true

liquibase:
contexts: prod

server:
port: 8080
compression:
    enabled: true
    mime-types: text/html,text/xml,text/plain,text/css, application/javascript, application/json
    min-response-size: 1024

最佳答案

我添加了 spring-boot-starter-data-jest 库来构建脚本,build.gradle:

-    compile "org.springframework.boot:spring-boot-starter-data-elasticsearch"
+    compile "com.github.vanroy:spring-boot-starter-data-jest:2.2.0.RELEASE"

在应用程序类 App.java 中添加了对 ElasticsearchAutoConfiguration 和 ElasticsearchDataAutoConfiguration 的排除:

@ComponentScan
+@EnableAutoConfiguration(exclude = {
+    ElasticsearchAutoConfiguration.class, ElasticsearchDataAutoConfiguration.class })
@EnableConfigurationProperties({ JHipsterProperties.class, LiquibaseProperties.class })
public class App {

并改变了:

import org.elasticsearch.client.Client;
-import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.EntityMapper;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.github.vanroy.springdata.jest.JestElasticsearchTemplate;
+import com.github.vanroy.springdata.jest.mapper.DefaultJestResultsMapper;
+import io.searchbox.client.JestClient;

@Configuration
public class ElasticSearchConfiguration {

  @Bean
-    public ElasticsearchTemplate elasticsearchTemplate(Client client, Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder) {
-        return new ElasticsearchTemplate(client, new CustomEntityMapper(jackson2ObjectMapperBuilder.createXmlMapper(false).build()));
+    public JestElasticsearchTemplate elasticsearchTemplate(JestClient client, Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder) {
+        return new JestElasticsearchTemplate(client, new DefaultJestResultsMapper(
+                new CustomEntityMapper(jackson2ObjectMapperBuilder.createXmlMapper(false).build())));
  }

然后我添加了配置参数,文件application.yml:

+    data:
+        elasticsearch:
+            properties:
+                path:
+                  home: target/elasticsearch
+                transport:
+                  tcp:
+                      connect_timeout: 120s
        jest:
+            readTimeout: 10000
             uri: ${SEARCHBOX_SSL_URL}

关于spring - 在 Jhipster 中设置 bonsai-elasticsearch - Heroku,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39623238/

相关文章:

session - heroku 上的 Redis session 存储

elasticsearch - 瑞典分析仪使用哪些关键字?

elasticsearch - Logstash 配置文件错误(Answer not working)

azure - 如何连接到Azure上安装的多个节点的elasticsearch集群?如何获取elasticsearch端点?

java - 为 Ldap 连接配置 Spring 安全性

java - 如何在 Spring Boot 中区分具有相同名称但不同查询参数的 edpoint

mysql - SpringBoot JPA MappedBy 引用一个未知的目标实体属性

ruby-on-rails - NoMethodError(Heroku 的 Logger 未定义方法 `flush'

performance - 如何在 Heroku 上重置 pg_stat_user_tables? (pg_stat_reset() 需要 super 用户)

java - Spring/LDAP - 在 beans 配置中调用 setter 方法