Reputation: 33
I have this propelr.properties:
elasticsearch.port=443
elasticsearch.protocol=https
elasticsearch.index=contentlink
elasticsearch.type=cl
kafka.max-poll-records=1000
kafka.topic=es-indexer-topic
kafka.group.id=espn-content-link-kafka-es-connector-group
kafka.concurrency-level=4
And this file where I get the port:
@Component
final class ElasticSearchClientFactory extends
AbstractFactoryBean<RestHighLevelClient> {
private final RestHighLevelClient client;
ElasticSearchClientFactory(
final @Value("${elasticsearch.hostname}") String hostname,
final @Value("${elasticsearch.port}") int port,
final @Value("${elasticsearch.protocol}") String protocol
) {
client = new RestHighLevelClient(RestClient.builder(new
HttpHost(hostname, port, protocol)));
}
@Override
public Class<?> getObjectType() {
return RestHighLevelClient.class;
}
@Override
protected RestHighLevelClient createInstance() throws Exception {
return client;
}
@Override
public void destroy() throws Exception {
if (Objects.nonNull(client)) {
client.close();
}
}
}
And this portion of code is where the @Configuration is:
@EnableKafka
@Configuration
public class KafkaReceiverConfig {
@Value("${contentlink.kafka.bootstrap.servers}")
private String bootstrapServers;
@Value("${kafka.group.id}")
private String kafkaGroupId;
@Value("${kafka.max-poll-records}")
private String kafkaMaxPollRecords;
@Value("${kafka.concurrency-level}")
private int kafkaConcurrencyLevel;
private EspnMetricRegistry metricRegistry;
@Bean
public KafkaReceiver receiver(
@Value("${elasticsearch.index}") final String index,
@Value("${elasticsearch.type}") final String type,
final RestHighLevelClient client, final EspnMetricRegistry metricRegistry) {
return new KafkaReceiver(index, type, metricRegistry, client);
}
@Bean
public ConcurrentKafkaListenerContainerFactory<String, ESPNEntity> kafkaListenerContainerFactory() {
ConcurrentKafkaListenerContainerFactory<String, ESPNEntity> factory =
new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(kafkaConsumerFactory());
factory.setBatchListener(true);
factory.setConcurrency(kafkaConcurrencyLevel);
return factory;
}
@Bean
public ConsumerFactory<String, ESPNEntity> kafkaConsumerFactory() {
final Deserializer<String> key = new StringDeserializer();
final Deserializer<ESPNEntity> value = new ESPNEntitySerde(new ESPNEntityConverter());
return new DefaultKafkaConsumerFactory<>(consumerConfigs(), key, value);
}
@Bean
public Map<String, Object> consumerConfigs() {
Map<String, Object> props = new HashMap<>();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, ESPNEntitySerde.class);
props.put(ConsumerConfig.GROUP_ID_CONFIG, kafkaGroupId);
props.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, kafkaMaxPollRecords);
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
return props;
}
}
So, I don't know what could be causing this error or what I'm missing but when I deploy to aws, the stack gets stuck because when it reaches the part of the springboot, it fails and it throws these errors:
2018-12-19 16:28:45.381 ERROR 43 --- [ main] o.s.boot.SpringApplication : Application startup failed
java.lang.IllegalArgumentException: Could not resolve placeholder 'elasticsearch.port' in value "${elasticsearch.port}"
Upvotes: 3
Views: 5003
Reputation: 2007
You need to register your properties file. Add this line under @Component annotation:
@PropertySource("classpath:propelr.properties")
So it should looks like this:
@Component
@PropertySource("classpath:propelr.properties")
final class ElasticSearchClientFactory extends
AbstractFactoryBean<RestHighLevelClient> {
private final RestHighLevelClient client;
ElasticSearchClientFactory(
final @Value("${elasticsearch.hostname}") String hostname,
final @Value("${elasticsearch.port}") int port,
final @Value("${elasticsearch.protocol}") String protocol
) {
client = new RestHighLevelClient(RestClient.builder(new
HttpHost(hostname, port, protocol)));
}
@Override
public Class<?> getObjectType() {
return RestHighLevelClient.class;
}
@Override
protected RestHighLevelClient createInstance() throws Exception {
return client;
}
@Override
public void destroy() throws Exception {
if (Objects.nonNull(client)) {
client.close();
}
}
}
EDIT Static property source placeholder
@Bean
public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
return new PropertySourcesPlaceholderConfigurer();
}
Upvotes: 5
Reputation: 39
As @Rafal referred, you should specify the @propertySource("classpath:application.properties") you have to give the correct path and the file name you want your property to be read from.
Upvotes: 0