Open sats17 opened 4 years ago
Hi @sats17 , are you sure that you have exclude ElasticSearchAutoConfiguration like this :
@SpringBootApplication(exclude = {ElasticsearchAutoConfiguration.class, ElasticsearchDataAutoConfiguration.class})
And that at least this properties is set :
spring:
data:
jest:
uri: http://localhost:9200
Hi @VanRoy,
I did all what you mentioned, It's my bad that I was just searching beans with bean names. But later that I found bean for JestElasticSearchTemplate which is
"elasticsearchTemplate": { "aliases": [], "scope": "singleton", "type": "com.github.vanroy.springdata.jest.JestElasticsearchTemplate", "resource": "class path resource [com/github/vanroy/springboot/autoconfigure/data/jest/ElasticsearchJestDataAutoConfiguration.class]", "dependencies": [ "testClient" ] },
As of now I can see that if I did like below, my project compiles without any error.
@Autowired private ElasticsearchOperations esTemplate;
@Autowired private JestElasticsearchTemplate jestTemplate;
But if I swapped the positions or remove the ElasticsearchOperations, then spring boot not able to found bean for JestElasticsearchTemplate.
@Autowired private JestElasticsearchTemplate jestTemplate;
@Autowired private ElasticsearchOperations esTemplate;
Hi @sats17, Indeed it's really strange 😄 . I will investigate on it.
Hi @VanRoy , I have attached the zip file of the test project which is having this bean problem.
Hi @sats17 , thanks a lot for your additionnals informations.
Indeed, currently SpringDataJest expose his JestElasticsearchTemplate
bean as ElasticsearchOperations
type.
For now your best option to use JestElasticsearchTemplate
is to do something like that 👍
public class MyClass {
private final JestElasticsearchTemplate jestTemplate;
public MyClass(ElasticsearchOperations esTemplate) {
this.jestTemplate = (JestElasticsearchTemplate)esTemplate;
}
I a futur release I will probably change the type of the JestElasticsearchTemplate
bean from ElasticsearchOperations
to JestElasticsearchTemplate
but I need to check the possible impacts.
Again, thanks for your help during the investigation. Julien.
Hi @VanRoy ,
Thanks for the clarification :smiley:
Hi @VanRoy , I tried to autowire the JestElasticsearchTemplate and it is returning below error.
Action: Consider defining a bean of type 'com.github.vanroy.springdata.jest.JestElasticsearchTemplate' in your configuration.
for code
@Service public class ElasticSearchService { @Autowired private JestElasticsearchTemplate template; }
and dependency I am using is
After checking all beans that is created in my application I did not found any bean for JestElasticsearchTemplate. But I see bean for elasticsearchTemplate is created.
Also when I am not getting any exception when I am autowiring an interface
@Autowired private ElasticsearchOperations template;
and after the getting class of above template class variable I can see it is pointing to JestElasticsearchTemplate class, but again after this I checked all beans which is created in Container I did not found JestElasticsearchTemplate bean is created.
It all looks strange to me as 1) Error is throwing for JestElasticsearchTemplate while performing autowiring on that. 2) How in my container I did not found any bean name as JestElasticsearchTemplate. 3) And even if there is not any bean created in my container how @Autowired private ElasticsearchOperations template is pointing to JestElasticsearchTemplate class.