[英]Setting up bonsai-elasticsearch in Jhipster - Heroku
在部署到Heroku我的Jhipster應用程序后,我想使用雲彈性搜索(Bonsai)和JHipster。 盆景提供以下env變量:
$BONSAI_URL
如何在application-prod.yml中正確添加? 我一直在閱讀文檔,並嘗試將其設置為集群節點值和主機。 但我有點失落。 任何提示都非常受歡迎。
應用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())));
}
然后我添加了configuraiton參數,文件application.yml
:
+ data:
+ elasticsearch:
+ properties:
+ path:
+ home: target/elasticsearch
+ transport:
+ tcp:
+ connect_timeout: 120s
jest:
+ readTimeout: 10000
uri: ${SEARCHBOX_SSL_URL}
這項工作對我來說:
輸入console heroku config:get BONSAI_URL -a YOUR_HEROKU APP NAME
;
你會得到這樣的東西:
https://xaawlsdv2z:dvt345cl1dk@jasm3ne-1113487.eu-west-1.bonsaisearch.net
在application-prod.yml
:
data:
elasticsearch:
jest:
uris: https://jasm3ne-1113487.eu-west-1.bonsaisearch.net:443
read-timeout: 10000
username: xaawlsdv2z
password: dvt345cl1dk
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.