标签:
1.增加Maven POM文件的存储库:pom配置如下:
<repositories> <repository> <id>spring-milestone</id> <name>Spring Milestone Maven Repository</name> <url>http://repo.springsource.org/libs-milestone</url> </repository> </repositories>
2.添加依赖关系,也就是所需要的Jar包:修改pom.xml文件:
<!-- Spring Data Solr --> <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>
或
<!-- spring data solr --> <dependency> <groupId>org.apache.solr</groupId> <artifactId>solr-core</artifactId> <version>4.5.0</version> <exclusions> <exclusion> <artifactId>slf4j-log4j12</artifactId> <groupId>org.slf4j</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-annotations</artifactId> <version>2.0.5-alpha</version> <exclusions> <exclusion> <groupId>jdk.tools</groupId> <artifactId>jdk.tools</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-solr</artifactId> <version>1.0.0.RELEASE</version> <scope>compile</scope> </dependency> <!-- spring data solr end -->
或
<dependency> <groupId>org.apache.solr</groupId> <artifactId>solr-solrj</artifactId> <version>4.5.0</version> <exclusions> <exclusion> <artifactId>slf4j-log4j12</artifactId> <groupId>org.slf4j</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-solr</artifactId> <version>1.5.0.RELEASE</version> <scope>compile</scope> </dependency>
3.Spring配置
<?xml version="1.0" encoding="UTF-8"?> <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>
或
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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-3.1.xsd http://www.springframework.org/schema/data/solr http://www.springframework.org/schema/data/solr/spring-solr-1.0.xsd " default-lazy-init="true"> <description>DADA USER MGMT INDEX 公共配置文件 </description> <!-- Solr 配置 --> <!-- Enable Solr repositories and configure repository base package --> <solr:solr-server id="solrServer" url="${solr.serverurl}" /> <bean id="solrTemplate" class="org.springframework.data.solr.core.SolrTemplate"> <constructor-arg index="0" ref="solrServer"/> </bean> <solr:repositories base-package="com.wzitech.slq" /> </beans>
标签:
原文地址:http://www.cnblogs.com/Crow0/p/5119611.html