Reputation: 1751
In my spring boot application I have the elasticsearch 5.4 transport client connection.
@Configuration
public class EsConfig {
@Value("${elastic.host}")
private String esHost;
@Value("${elastic.port}")
private int esPort;
@Bean
public TransportClient client() throws Exception {
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(esHost), esPort));
return client;
}
}
I need to get the instance inside service class to use it in my operation.
@Service
public class ElasticService {
TransportClient client;
public String getInfo(){
client.methodCall() ...
}
}
How can I autowire the client object defined inside ElasticService.
Upvotes: 0
Views: 61
Reputation: 217474
How about this?
@Service
public class ElasticService {
@Autowired <---- add this annotation
TransportClient client;
public String getInfo(){
}
}
Upvotes: 1