[DATASOLR-304] Allow PropertyPlaceholders in @SolrDocument solrCoreName Created: 03/May/16  Updated: 13/Feb/20

Status: Open
Project: Spring Data for Apache Solr
Component/s: Namespace
Affects Version/s: 2.0.1 (Hopper SR1), 1.5.4 (Gosling SR4)
Fix Version/s: None

Type: Improvement Priority: Major
Reporter: David Webb Assignee: Christoph Strobl
Resolution: Unresolved Votes: 11
Labels: Neumann, solr, spring-data
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
is superseded by DATASOLR-463 Allow SpEL expressions for collection... Closed
Last updater: Christoph Strobl


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 {

	private String guid;

	private String jobTitle;

	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}

Comment by Ananth Ramchandran [ 06/Jun/16 ]

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)

Comment by Sunilkumar Peljur [ 15/May/17 ]

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

Comment by Fei Tian [ 16/Oct/17 ]

I have exactly same requirement for this feature

Comment by Shujathullah Mirza [ 20/Aug/18 ]

Is there any update on this ticket ?? 

Comment by Paul Wellner Bou [ 21/Aug/18 ]

Shujathullah Mirza, 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.

Comment by David Webb [ 21/Aug/18 ]

Thats a nice solution Paul Wellner BouChristoph Strobl and/or Oliver Gierke, 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.

Comment by Paul Wellner Bou [ 06/Apr/19 ]

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


Comment by kaszuster [ 15/Oct/19 ]

Following the example in the docs 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 


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.

Comment by Christoph Strobl [ 16/Oct/19 ]

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.

Comment by kaszuster [ 16/Oct/19 ]

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

Comment by yoyo tom [ 21/Oct/19 ]

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

Comment by kaszuster [ 21/Oct/19 ]

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;

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

    String solrURL;

    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();

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

    @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
    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

    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.


Comment by yoyo tom [ 22/Oct/19 ]

kaszuster Thanks a lot! Adding the converters solved the problem

Generated at Fri Aug 14 14:17:30 UTC 2020 using Jira 8.5.4#805004-sha1:0444eab799707f9ad7b248d69f858774aadfd250.