Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JestElasticsearchTemplate not able to do AutoWired. #148

Open
sats17 opened this issue Oct 21, 2020 · 6 comments
Open

JestElasticsearchTemplate not able to do AutoWired. #148

sats17 opened this issue Oct 21, 2020 · 6 comments
Labels

Comments

@sats17
Copy link

sats17 commented Oct 21, 2020

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

com.github.vanroy
spring-boot-starter-data-jest
3.3.0.RELEASE

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.
@VanRoy
Copy link
Owner

VanRoy commented Oct 22, 2020

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

@sats17
Copy link
Author

sats17 commented Oct 24, 2020

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;

@VanRoy
Copy link
Owner

VanRoy commented Nov 1, 2020

Hi @sats17, Indeed it's really strange 😄 . I will investigate on it.

@sats17
Copy link
Author

sats17 commented Nov 28, 2020

Hi @VanRoy ,
I have attached the zip file of the test project which is having this bean problem.

test.zip

@VanRoy
Copy link
Owner

VanRoy commented Dec 4, 2020

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.

@sats17
Copy link
Author

sats17 commented Dec 5, 2020

Hi @VanRoy ,

Thanks for the clarification 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants