In the previous part of my Spring Data Solr tutorial, we learned that Solr provides a REST-like HTTP API which can be used to add information to Solr index and execute queries against indexed data. The problem is that running a separate Solr instance in a development environment is a bit cumbersome.
However, not all hope is lost because Solr provides two alternative server implementations which we can use in our applications. These implementations are described in the following:
- The embedded Solr server connects directly to Solr core. We can use this server for development purposes but we must also remember that using it in production environment is not recommended. However, using the embedded Solr server is still a viable option in the development environment.
- The HTTP Solr server connects to an external Solr server by using HTTP. This is the recommended way of using the Solr search server and that is why we should always use it in the production environment.
This blog entry describes how we can get the required dependencies with Maven. We also learn to configure the Spring Data Solr to use the embedded Solr server in the development environment and the HTTP Solr server in the production environment.
Note: These blog entries provides additional information which helps us to understand the concepts described in this blog entry:
Let’s get started.
Getting the Required Dependencies with Maven
We can get the required dependencies with Maven by following these steps:
- Add the Spring Milestone Maven repository to the POM file.
- Add the required dependencies to the pom.xml file.
Both of these steps are described with more details in the following.
Adding the Spring Milestone Maven Repository to the POM File
We can add the Spring milestone Maven repository to our POM file by adding the following XML to the pom.xml file:
<repository>
<id>spring-milestone</id>
<name>Spring Milestone Maven Repository</name>
<url>http://repo.springsource.org/libs-milestone</url>
</repository>
</repositories>
Adding the Required Dependencies to the POM File
We can add the required dependencies to the POM file by following these steps:
- Add the Spring Data Solr dependency (version 1.0.0.RC1) to the dependencies section of our POM file.
- Add the Solr core dependency (version 4.1.0) to the dependencies section of our POM file and exclude the SLF4J JDK14 binding. Because Solr core is required by the embedded Solr server, we can skip this step if we are not using the embedded Solr server.
We can complete these steps by adding the following XML to the dependencies section of the POM file:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
<version>1.0.0.RC1</version>
</dependency>
<!-- Required by embedded solr server -->
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
<version>4.1.0</version>
<exclusions>
<exclusion>
<artifactId>slf4j-jdk14</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
Configuring Spring Data Solr
This section describes how we can configure Spring Data Solr to use different Solr servers in the development and production environment. We will use the embedded Solr server in the development environment and the HTTP Solr server in the production environment.
We can configure Spring Data Solr by following these steps:
- Create a properties file.
- Configure the embedded Solr server.
- Configure the HTTP Solr server.
- Set the active bean definition profile.
These steps are described with more details in the following subsections.
Creating the Properties File
The name of our properties file is application.properties and we will use it to configure two properties which are described in the following:
- The solr.server.url property specifies the url of the used Solr server. The value of this property is used to configure the HTTP Solr server which is used in the production environment.
- The solr.solr.home configures the home directory of Solr. The value of this property is used to configure the home directory of the embedded Solr server which is used in the development environment.
The content of the application.properties file looks as follows:
solr.solr.home=
Configuring the Embedded Solr Server
This subsection describes how we can configure Spring Data Solr to use the embedded Solr server in the development environment.
Java Configuration
We can create a configuration class which configures the embedded Solr server by following these steps:
- Create a class called EmbeddedSolrContext and annotate that class with the @Configuration annotation.
- Enable Spring Data Solr repositories by annotating that class with the @EnableSolrRepositories annotation and configuring the root package of our Solr repositories.
- Annotate the created class with the @Profile annotation and set its value to ‘dev’. This means that this configuration class is bypassed unless the ‘dev’ profile have been activated.
- Annotate the class with the @PropertySource annotation and set its value to ‘classpath:application.properties’. This configures the location of our property file and adds a PropertySource to Spring’s Environment.
- Add an Environment field to the class and annotate that field with the @Resource annotation. The injected Environment is used to access the properties which we added to our properties file.
- Create a method called solrServerFactoryBean() and annotate this method with the @Bean annotation. The implementation of this method creates a new EmbeddedSolrServerFactoryBean object, sets the value of the Solr home and returns the created object.
- Create a method called solrTemplate() and annotate this method with the @Bean annotation. The implementation of this method creates a new SolrTemplate object and passes the used SolrServer implementation as a constructor argument.
The source code of the EmbeddedSolrContext class looks as follows:
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.data.solr.core.SolrTemplate;
import org.springframework.data.solr.repository.config.EnableSolrRepositories;
import org.springframework.data.solr.server.support.EmbeddedSolrServerFactoryBean;
import javax.annotation.Resource;
@Configuration
@EnableSolrRepositories("net.petrikainulainen.spring.datasolr.todo.repository.solr")
@Profile("dev")
@PropertySource("classpath:application.properties")
public class EmbeddedSolrContext {
@Resource
private Environment environment;
@Bean
public EmbeddedSolrServerFactoryBean solrServerFactoryBean() {
EmbeddedSolrServerFactoryBean factory = new EmbeddedSolrServerFactoryBean();
factory.setSolrHome(environment.getRequiredProperty("solr.solr.home"));
return factory;
}
@Bean
public SolrTemplate solrTemplate() throws Exception {
return new SolrTemplate(solrServerFactoryBean().getObject());
}
}
XML Configuration
We can create an XML configuration file for the embedded Solr server by following these steps:
- Configure the used properties file by using the property-placeholder element of the context namespace.
- Enable Solr repositories and configure the base package of our Solr repositories by using the repositories element of the solr namespace.
- Create a bean configuration for the development profile.
- Configure the embedded Solr server bean by using the embedded-solr-server element of the solr namespace. Set the value of the Solr home.
- Configure the Solr template bean. Set the configured embedded Solr server bean as constructor argument.
The contents of the exampleApplicationContext-solr.xml file looks as follows:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:solr="http://www.springframework.org/schema/data/solr"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/data/solr http://www.springframework.org/schema/data/solr/spring-solr.xsd">
<context:property-placeholder location="classpath:application.properties"/>
<!-- Enable Solr repositories and configure repository base package -->
<solr:repositories base-package="net.petrikainulainen.spring.datasolr.todo.repository.solr"/>
<!-- Bean definitions for the dev profile -->
<beans profile="dev">
<!-- Configures embedded Solr server -->
<solr:embedded-solr-server id="solrServer" solrHome="${solr.solr.home}"/>
<!-- Configures Solr template -->
<bean id="solrTemplate" class="org.springframework.data.solr.core.SolrTemplate">
<constructor-arg index="0" ref="solrServer"/>
</bean>
</beans>
<!-- Bean definitions for the prod profile are omitted -->
</beans>
Configuring the Http Solr Server
This subsection describes how we can configure Spring Data Solr to use the HTTP Solr server in the production environment.
Java Configuration
We can create a configuration class which configures the HTTP Solr server by following these steps:
- Create a class called HttpSolrContext and annotate that class with the @Configuration annotation.
- Enable Spring Data Solr repositories by annotating that class with the @EnableSolrRepositories annotation and configuring the root package of our Solr repositories.
- Annotate the created class with a @Profile annotation and set its value to ‘prod’. This means that this configuration class is bypassed unless the ‘prod’ profile have been activated.
- Annotate the class with the @PropertySource annotation and set its value to ‘classpath:application.properties’. This configures the location of our property file and adds a PropertySource to Spring’s Environment.
- Add an Environment field to the class and annotate that field with the @Resource annotation. The injected Environment is used to access the properties which we added to our properties file.
- Create a method called solrServerFactoryBean() and annotate this method with the @Bean annotation. The implementation of this method create a new HttpSolrServerFactoryBean object, sets the value of the Solr server url and returns the created object.
- Create a method called solrTemplate() and annotate this method with the @Bean annotation. The implementation of this method creates a new SolrTemplate object and passes the used SolrServer implementation as a constructor argument.
The source code of the HttpSolrContext class looks as follows:
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.data.solr.core.SolrTemplate;
import org.springframework.data.solr.repository.config.EnableSolrRepositories;
import org.springframework.data.solr.server.support.HttpSolrServerFactoryBean;
import javax.annotation.Resource;
@Configuration
@EnableSolrRepositories("net.petrikainulainen.spring.datasolr.todo.repository.solr")
@Profile("prod")
@PropertySource("classpath:application.properties")
public class HttpSolrContext {
@Resource
private Environment environment;
@Bean
public HttpSolrServerFactoryBean solrServerFactoryBean() {
HttpSolrServerFactoryBean factory = new HttpSolrServerFactoryBean();
factory.setUrl(environment.getRequiredProperty("solr.server.url"));
return factory;
}
@Bean
public SolrTemplate solrTemplate() throws Exception {
return new SolrTemplate(solrServerFactoryBean().getObject());
}
}
XML Configuration
We can create an XML configuration file for the HTTP Solr server by following these steps:
- Configure the used properties file by using the property-placeholder element of the context namespace.
- Enable Solr repositories and configure the base package of our Solr repositories by using the repositories element of the solr namespace.
- Create a bean configuration for the production profile.
- Configure the HTTP Solr server bean by using the solr-server element of the solr namespace. Set the url of the Solr server.
- Configure the Solr template bean. Set the configured HTTP Solr server bean as a constructor argument.
The content of the exampleApplicationContext-solr.xml file looks as follows:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:solr="http://www.springframework.org/schema/data/solr"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/data/solr http://www.springframework.org/schema/data/solr/spring-solr.xsd">
<context:property-placeholder location="classpath:application.properties"/>
<!-- Enable Solr repositories and configure repository base package -->
<solr:repositories base-package="net.petrikainulainen.spring.datasolr.todo.repository.solr"/>
<!-- Bean definitions for the dev profile are omitted -->
<!-- Bean definitions for the prod profile -->
<beans profile="prod">
<!-- Configures HTTP Solr server -->
<solr:solr-server id="solrServer" url="${solr.server.url}"/>
<!-- Configures Solr template -->
<bean id="solrTemplate" class="org.springframework.data.solr.core.SolrTemplate">
<constructor-arg index="0" ref="solrServer"/>
</bean>
</beans>
</beans>
Setting the Active Bean Definition Profile
We can select the active bean definition profile by setting the value of the spring.profiles.active system variable. The allowed values of this system variable (in the context of our example application) are described in the following:
- We can configure our application to run in the development profile by setting the value of the spring.profiles.active system variable to ‘dev’.
- When we want configure our application to run in the production profile, we have to set the of the spring.profiles.active system variable to ‘prod’.
We can configure our example application to support both profiles by following these steps:
- Add required profiles to the POM file.
- Create the profile specific properties files for system properties.
- Configure the Jetty Maven plugin.
These steps are described with more details in the following.
Adding the Required Profiles to the POM File
We can add the required profiles to our Maven build by following these steps:
- Create a profile for development environment. Set the id of this profile to ‘dev’ and set the value of the build.profile.id property to ‘dev’.
- Create a profile for the production environment. Set the id of this profile to ‘prod’ and set the value of the build.profile.id property to ‘prod’.
The configuration of our Maven profiles looks as follows:
<profile>
<id>dev</id>
<properties>
<build.profile.id>dev</build.profile.id>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<build.profile.id>prod</build.profile.id>
</properties>
</profile>
</profiles>
Creating the Profile Specific Properties Files for System Properties
The profile specific properties files are located in the sub directories of the profiles directory. The name of each sub directory matches with the values of the build.profile.id properties configured in the pom.xml file.
We can create the profile specific properties files for system properties by following these steps:
- Create a properties file called system.properties to the profiles/dev directory. This properties file contains the system properties of the development profile.
- Create a properties file called system.properties to the profiles/prod directory. This properties file contains the system properties of the production profile.
The content of the properties file used to configure the system properties of the development profile looks as follows:
The content of the properties file used to configure the system properties of the production profile looks as follows:
Configuring the Jetty Maven Plugin
We can configure the Jetty Maven plugin by following these steps:
- Add the plugin declaration of the Jetty Maven plugin to the plugins section of our Pom file.
- Configure the stopKey and stopPort of the Jetty Maven plugin.
- Configure the location of the properties file containing the used system properties.
The configuration of the Jetty Maven plugin looks as follows:
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.5.v20120716</version>
<configuration>
<stopKey>todostop</stopKey>
<stopPort>9999</stopPort>
<systemPropertiesFile>${project.basedir}/profiles/${build.profile.id}/system.properties</systemPropertiesFile>
</configuration>
</plugin>
Summary
We have now successfully obtained the required dependencies with Maven and configured Spring Data Solr. This blog entry has taught us four things:
- We learned to get the required dependencies with Maven.
- We know that we should use the embedded Solr server only in the development environment and learned how we can configure Spring Data Solr to use it.
- We learned that we should always use the HTTP Solr server in the production environment and know how we can configure Spring Data Solr to use it.
- We know how we can use the bean definition profiles of Spring Framework for creating different configurations for development and production environment.
The next part of my Spring Data Solr tutorial describes how we can add new document to Solr index, update the information of an existing documents and delete documents from the Solr index.
PS. The example application of this blog entry is available at Github.







Kumar Chandran February 21, 2013 at 3:54 am
HI,
The spring data solr tutorial that you have posted is one of the best I have found on the internet. It is very detailed and comprehensive.
In your spring data solr tutorial you have mentioned “The next part of my Spring Data Solr tutorial describes how we can add new document to Solr index, update the information of an existing documents and delete documents from the Solr index” but I was unable to find continuation to the last part of this tutorial. Please let me know if there is a link to the post that describes how to add new document to solr index…
Would appreciate your response…
Regards,
Kumar
Petri February 21, 2013 at 10:13 am
Thank you for the compliment. It is always nice to get positive feedback.
I have not written the next part of this tutorial yet but the example application already has this functionality.
I am planning to write the next part during the weekend and publish it before Monday.
Ssm April 1, 2013 at 8:20 am
How to integrate it with Tomcat7?
Petri April 1, 2013 at 11:08 am
When the application is deployed to Tomcat, you can specify the active profile by adding the following line to the
conf/catalina.propertiesfile:spring.profiles.active=devRemember that the value of the
spring.profiles.activeproperty depends from the profile which you want to use.Ssm April 2, 2013 at 8:50 am
Hi,
Thanks for the response, and also wanted to know like how to index and query html files in a directory using spring-data-solr
Thanks.
Petri April 4, 2013 at 9:54 am
The first thing which you have to do is to add the content of these documents to the Solr index. You have two options for doing this:
If you you select option number one, you might want to check out the following resources:
If you select option number two, you have to implement an indexing component which processes the HTML files and adds the indexed text to the Solr index by using Spring Data Solr. You might want to read the next part of my Spring Data Solr tutorial which describes how you can implement a CRUD application with Spring Data Solr.
If you want to learn how you can execute queries against indexed data by using Spring Data Solr, you should read these blog posts:
I hope that this answered to your question.
amit singh May 10, 2013 at 9:13 pm
Hi where is this configuration file..
Petri May 10, 2013 at 9:54 pm
Which configuration file?
Tom April 11, 2013 at 5:43 am
Hi, I can use this search English content,but not Chinese, I use Lucke and I can see all the content has been indexed properly. I want to know whether is my problem of solr configuration or my spring data solr search. My repository just like this:
@Query(“name:*?0* or description:*?0* or type:*?0* or mac_address:*?0* or uri:*?0* or attrs:*?0*”)
Page find(String keyword,Pageable page);
And I can search my Chinese content just use “*”,but can’t get anything by using specific Chinese word.
I will be very appreciative if you can give me a hint.Thanks.
Petri April 11, 2013 at 9:41 am
Hi,
The query seems to be correct. If the Chinese text is indexed property as you said, the problem can be that
In order to determine the root cause of problem, it would be important that you would answer to the following questions:
As a side note, indexing Chinese seems to be a bit trickier than I originally thought. I found a blog post called Indexing Chinese in Solr which has a brief overview about this. However, that blog post is not very detailed and it would be interesting to find a more comprehensive tutorial about this. If you know any, let me know. :)
amit singh May 10, 2013 at 3:54 pm
I am getting folowwing error
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘repositoryTodoService’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘repositoryTodoIndexService’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [net.petrikainulainen.spring.datasolr.todo.repository.solr.TodoDocumentRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency
While i am able to run the test cases. Please help me on this. I found this very useful but it is not working for me.
Petri May 10, 2013 at 4:23 pm
The root cause of this problem is that you have not configured the correct Spring profile for integration tests. If you run the integration tests by using the following command:
mvn clean verify -P integration-test
The correct Spring profile is set by Maven. If you are running the integration tests from your IDE, you have to set the active profile yourself. In other words, you have to add the following line to the JUnit configuration of your IDE:
-Dspring.profiles.active=test
Here are links to webpages which describe how you can do this:
I hope that this answered to your question.
amit singh May 10, 2013 at 4:50 pm
I am getting the error at starting up the jetty. more that there is no web.xml so that i can test the same on tomcat. if i do mvn install it gives no error and runs the tes cases.
Petri May 10, 2013 at 5:06 pm
The root cause is the same (The correct Spring profile is not set).
If you start Jetty by using a command:
mvn clean jetty:run, the active profile is set by Maven (I just tested this by running the example application myself).If you are using the standalone Jetty, you have to configure the correct profile manually. In other words, you have to add one of the following lines to the Jetty configuration:
#Add this if you want to use embedded Solr server
-Dspring.profiles.active=dev
#add this if you want to use HTTP Solr server
-Dspring.profiles.active=prod
Check out the chapter 16 of the Jetty user’s manual for more details about this.
You can also deploy the created war file to Tomcat 7 because it supports the Servlet 3.0 specification. This comment explains how you can configure the active profile when you are using Tomcat 7.
I hope that this answered to your question.
amit singh May 10, 2013 at 4:53 pm
I am not able to run the jetty server even on dev environment.
Petri May 10, 2013 at 5:09 pm
How are you trying to run it?
amit singh May 10, 2013 at 6:09 pm
I have solr running on tomcat at 9080. I am running this code through maven jetty. I pointed it to dev environment.
Petri May 10, 2013 at 6:24 pm
If you want to use the HTTP Solr server, you cannot use the ‘dev’ profile because it is configured to use the embedded Solr server. In this case, you have to use the ‘prod’ profile.
Also, since Solr is not running in the default port, you have to set the value of the
solr.server.urlproperty. You can find this property from the profiles/prod/config.properties file. After this is done, you can run the example application by running the commandmvn clean jetty:run -P prodat the command prompt (assuming that you are using the schema described in this blog post).If you want to use a standalone server, you have to set the active Spring profile manually. Check out my previous comment for more details about this.
amit singh May 10, 2013 at 6:34 pm
Thanx very much !! it worked as you said.. i needed to point to production.
Petri May 10, 2013 at 6:53 pm
You are welcome! I am happy to hear that you could solve your problem.
amit singh May 10, 2013 at 6:55 pm
Just want to understand couple of things. What all i need to do to get web.xml
Petri May 10, 2013 at 7:39 pm
If you want the replace the configuration class (
ExampleApplicationConfig) with a web.xml file, you can follow these steps:ExampleApplicationConfigclass.DispatcherServletconfiguration to the web.xml file. See the reference manual of Spring Framework for more details about this. Remember to map the dispatcher servlet to the url pattern ‘/’.ExampleApplicationContextclass.That should do the trick.
amit singh May 10, 2013 at 8:01 pm
Thanx a bunch !!!! I got it.. do you have any default user id and password to access the application…
amit singh May 10, 2013 at 8:27 pm
thanx got it working… thanx for your support and such a nice tutorial..
Petri May 10, 2013 at 8:50 pm
I guess you figured out that the credentials are user / password :) Anyway, good to hear that I could help you out.
amit singh May 10, 2013 at 9:30 pm
More i am reading and it is getting more interesting to explore…. I got it working in tomcat but now getting error on tomcat….
127.0.0.1 – - [10/May/2013:23:52:48 +0530] “GET /spring%2Ddata%2Dsolr%2Dcriteria/ HTTP/1.1″ 200 10580
127.0.0.1 – - [10/May/2013:23:52:48 +0530] “GET /static/css/example.css HTTP/1.1″ 404 995
127.0.0.1 – - [10/May/2013:23:52:48 +0530] “GET /static/js/vendor/bootstrap-transition.js HTTP/1.1″ 404 1031
all js files are 404 response. while if run the application on jetty it is working
Petri May 10, 2013 at 10:53 pm
This is a limitation of the example application. The problem is that the static resources are loaded by using absolute paths. That is why they are found only if the web application is found from context path ‘/’. You have two options for solving this problem:
I hope that this solved your problem.
amit singh May 10, 2013 at 11:09 pm
You rock Petri !!!! i got every thing up and running in my application.
Petri May 10, 2013 at 11:10 pm
Great!
I decided to update the example application by using option number two. Now the context path is taken into account when static resources are loaded. Thanks for pointing this problem out!
amit singh May 13, 2013 at 2:20 pm
I am using it in application with xmlwebapplication content. Where can I mention to load the HttpSolrContext.java. I am not able to load this java file and hence not any repository.
Petri May 13, 2013 at 2:30 pm
The example application also has a working XML configuration for Spring application context. The embedded Solr server and the HTTP Solr server are configured in a separate XML file which is imported to the main configuration file by using the
importnamespace element.Read the section called Configuring Spring Data Solr for more details about this.
amit singh May 13, 2013 at 3:29 pm
Thanx Petri !! I successfully integrated it with my project.
Petri May 13, 2013 at 7:18 pm
You are welcome!
amit singh May 13, 2013 at 3:57 pm
Hi Petri, one question, is it possible to index images… i have requirement to index the profile of users and profile comprises the image also…. any suggestion on this would be great help. Thanx in adnvance.
Petri May 13, 2013 at 7:40 pm
I have no personal experience from this but it seems that you can extract metadata from different documents by using Apache Tika Apache Tika. Here are links to webpages which might be useful to you:
It seems that it is quite hard to find an exact answer to your question. Unfortunately, I am not able to give it either.
PeriS May 16, 2013 at 4:32 am
Petri,
The repository link does not have the spring-data-solr jar so its not getting pulled down. I checked their site, and its missing. So any ideas?
Petri May 16, 2013 at 8:39 am
Which repository url are you using?
I noticed yesterday that the url http://repo.springframework.org/milestone does not work. Then I checked the homepage of the Spring Data Solr project and noticed that the repository url has changed to http://repo.springsource.org/libs-milestone. After I updated the repository url to the POM files of my Spring Data Solr examples, I could download all the dependencies from Maven repositories.
Peri May 16, 2013 at 8:48 pm
Thanks, will give it a shot. Would you recommend this approach (spring based model), as I m not sure if Spring is going to be actively working on evolving this solr support.
Petri May 16, 2013 at 11:08 pm
I am using Spring Data Solr in a production system without any problems. However, it is true that since the Spring Data Solr is not an official Spring project, it might not have as much resources than the official projects. I don’t think that this is necessarily a problem but of course you have to make your own mind about this. I can only say that if I had decided to use SolrJ, the codebase of that project would have a lot of boilerplate code. Spring Data Solr makes the code cleaner, shorter and faster to write.