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

Allow PropertyPlaceholders in @SolrDocument solrCoreName [DATASOLR-304] #422

Open
spring-projects-issues opened this issue May 3, 2016 · 13 comments

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented May 3, 2016

David Webb opened DATASOLR-304 and commented

There are situations where the name of a solrCore may change in different environments. Example is a Lower Level Env (LLE) solr cluster that has cores suffixed with _dev _qa _stage, etc.

As a developer, have the ability to use PropertyPlaceholders in solrCoreName attribute of the @SolrDocument Annotation.

@SolrDocument(solrCoreName = "${solr.job.core}")
public class JobDocument {

	@Id
	@Field
	private String guid;

	@Field("job_title")
	private String jobTitle;

	@Field("public_desc")
	private String description;

	public String getGuid() {
		return guid;
	}

	public void setGuid(String guid) {
		this.guid = guid;
	}

	public String getJobTitle() {
		return jobTitle;
	}

	public void setJobTitle(String jobTitle) {
		this.jobTitle = jobTitle;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

}

My attempts to do this with the latest Gosling SR4 and Hopper SR1 yields the following error that leads me to believe this is not currently supported and warrants an improvement request.

org.apache.solr.common.SolrException: Collection not found: ${solr.job.core}

Affects: 2.0.1 (Hopper SR1), 1.5.4 (Gosling SR4)

Issue Links:

  • DATASOLR-463 Allow SpEL expressions for collection in @SolrDocument
    ("is superseded by")

11 votes, 10 watchers

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jun 6, 2016

Ananth Ramchandran commented

Is there an update on this ticket ?? I have a similar requirement in my app where the core name needs to be dynamically changed based on the environment at run time. I would appreciate any help in this.Thanks. (spring boot version used 1.3.3.RELEASE)

Loading

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 15, 2017

Sunilkumar Peljur commented

Any update on this issue? I am also in need of this feature

Loading

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 16, 2017

Fei Tian commented

I have exactly same requirement for this feature

Loading

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Aug 20, 2018

Shujathullah Mirza commented

Is there any update on this ticket ?? 

Loading

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Aug 21, 2018

Paul Wellner Bou commented

Mirzaunstoppable, Sunilkumar Peljur, there is a workaround, but you will have to write a bit more code and you can't rely on the "magic" which is augenerating your query methods. See https://paul.wellnerbou.de/2018/08/21/using-spring-data-solr-with-configurable-solr-core/

Christoph Strobl, are there any plans to include a feature like this in future? If yes, I would try to create a pull request for you

Loading

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Aug 21, 2018

David Webb commented

Thats a nice solution Paul Wellner BouChristoph Strobl and/or ogierke, I would be happy to write this PR if you could point me to the an example of how this is done in other SD projects and the part of SDSolr that should apply the PropertyPlaceholder to the @SolrDocument annotation.  Thanks

Loading

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Apr 6, 2019

Paul Wellner Bou commented

This ticket is solved now, as I can read in the docs, correct?

I was pointed to this feature documented in the documentation in one of the comments of the blog entry I linked above: https://paul.wellnerbou.de/2018/08/21/using-spring-data-solr-with-configurable-solr-core/#comment-4411778925

 

Loading

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 15, 2019

kaszuster commented

Following the example in the [docs|https://docs.spring.io/spring-data/solr/docs/4.0.11.RELEASE/reference/html/#solr.misc.collection-name] gives me 

org.springframework.expression.spel.SpelEvaluationException: EL1057E: No bean resolver registered in the context to resolve access to bean 'collectionName'

as soon as i create a repository that extends 

SolrCrudRepository

However when i create a custom repository, i have to implement all crud operations by hand, to do that i have to use the SolrTemplate and there i have to provide a collection name anyway

Loading

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 16, 2019

Christoph Strobl commented

kaszuster can you please open a new issue related to DATASOLR-463 that describes the error in a bit more detail. If you have a failing test at hand that would be great

Loading

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 16, 2019

kaszuster commented

I did some more research and will try to open an issue later this day

Loading

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 21, 2019

yoyo tom commented

kaszuster did you find a workaround? I have the same error!

Loading

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 21, 2019

kaszuster commented

yoyo tom yes, i have been able to solve my problem, howover i dont know if this is going to help you:

  1. make sure you have the exact same error: "EL1057E: No bean resolver registered in the context to resolve access to bean 'collectionName'" this indicates, that no BeanFactory could be found to resolve the requested bean. There was another error message i have seen, that was very  simular but the cause was something completely differant.
  2. If you have defined you own SolrTemplate, make sure to provide the Default (or extended) converters. Providing no converter leads to this error.

 

Here is how my configuration looks like (I changed a downloaded example to reproduce the problem)

 

import org.springframework.data.solr.repository.config.AbstractSolrConfiguration;

@Configuration
@EnableSolrRepositories(solrTemplateRef = "mySolrTemplate", basePackages = "com.doj.app.repository")
@ComponentScan
public class SolrConfig extends AbstractSolrConfiguration {

    @Value("${spring.data.solr.host}")
    String solrURL;

    @Bean
    public SolrClient solrClient() {
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("followRedirects", false);
        params.set("allowCompression", false);
        params.set("httpBasicAuthUser", "USERNAME");
        params.set("httpBasicAuthPassword", "PASSWORD");
        CloseableHttpClient httpClient = HttpClientUtil.createClient(params);
        return new Builder(solrURL).withHttpClient(httpClient).build();
    }

    @Bean
    public String collectionName() {
        return "my-coll";
    }

    @Bean
    @ConditionalOnMissingBean(name = "solrTemplate")
    public SolrTemplate solrTemplate(@Qualifier("mySolrTemplate") SolrTemplate solrTemplate) {
        return solrTemplate;
    }
    
    // because i have more than one solr server connected, you can ignore this
    @Bean("mySolrTemplate")
    public SolrTemplate mySolrTemplate(SolrClient solrClient, SolrConverter solrConverter) {
        return new SolrTemplate(new HttpSolrClientFactory(solrClient), solrConverter); // this does work
        // return new SolrTemplate(new HttpSolrClientFactory(solrClient)); // this does not
    }

    @Override
    public SolrClientFactory solrClientFactory() {
        return new HttpSolrClientFactory(solrClient());
    }
}

I will try to create a new ticket and upload an example project as soon as i have finished my daily business

 

Hope this helps.

 

Loading

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 22, 2019

yoyo tom commented

kaszuster Thanks a lot! Adding the converters solved the problem

Loading

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

Successfully merging a pull request may close this issue.

None yet
2 participants