全文索引服务solr入门三之solrJ的应用

三. 使用solrJ和spring集成 再上一篇和上上一篇文章中我们先搭建了一个solr服务器和学习了solr服务器后台的使用,这一次我们将直接进入实战:和spring集成,在继承之前我们先看看所需要的solr的jar文件都是那些(spring的那些大家就自己玩吧,我相信都知道的) 所需的jar文件 直接上图片,就是图上的这些图片,当然大家可以自己找maven依赖(jar文件这个最简单了,没有的话一定会报classnotfoundException,加上就好了) 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:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd "> <!&#8211; 配置扫描包 &#8211;> <context:component-scan base-package="cn.bridgeli"/> <!&#8211; 配置注解驱动 &#8211;> <mvc:annotation-driven/> <!&#8211; jsp视图解析器 &#8211;> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" > <!&#8211; 前缀 &#8211;> <property name="prefix" value="/WEB-INF/jsp/"></property> <!&#8211; 后缀 &#8211;> <property name="suffix" value=".jsp"></property> </bean> <!&#8211; 单机版solr &#8211;> <bean class="org.apache.solr.client.solrj.impl.HttpSolrServer"> <constructor-arg name="baseURL" value="http://localhost:8080/solr/"></constructor-arg> </bean> <!&#8211; 集群版SolrCloud &#8211;> <!&#8211; <bean class="org.apache.solr.client.solrj.impl.CloudSolrServer"> <constructor-arg name="zkHost" value="127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183"></constructor-arg> <property name="defaultCollection" value="collection2"></property> </bean> &#8211;> </beans> 简单吧,大家只要注意到单机版就行了,因为我们这次只用到了单机版,下面就要看源码实现了 ...

June 26, 2016 · 3 min · 585 words · Bridge Li