- 浏览: 9398 次
- 性别:
- 来自: 北京
-
文章分类
最新评论
-
yangactive:
<div class="quote_title ...
ssh+compass实现收索 -
niu396212866:
我老师正在让我弄这个东西,所以看到你说的有视频,真的很是激动啊 ...
ssh+compass实现收索 -
sunting_bcwl:
我今天也看了那套视频,不错
ssh+compass实现收索
照着v512 刘伟老师做了一个ssh 集成compass 的小程序 最后的感觉是compass 很好很强大,我把我其中遇到的问题写出来,也许大家也会遇到,省下不必要的麻烦。
我的类库是 struts2+ hibernate3.2+spring2.5+ compass2.1
第一个问题,也是让我最崩溃的问题
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'compassIndexBuilder' defined in ServletContext resource [/WEB-INF/applicationContext-compass.xml]: Cannot resolve reference to bean 'compassGps' while setting bean property 'compassGps'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'compassGps' defined in ServletContext resource [/WEB-INF/applicationContext-compass.xml]: Cannot resolve reference to bean 'compass' while setting bean property 'compass'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'compass' defined in ServletContext resource [/WEB-INF/applicationContext-compass.xml]: Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit(IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)V
看到这么长的错,我首先感觉到的就是,自己的代码有问题,死劲的找没找到。在网上搜了一下发现原来这错挺常见,我就按别人的提示一个一个的试,最终在http://atao.iteye.com/blog/281282 找到了答案,是由于Spring中的“asm-2.2.3.jar”和Hibernate中的“asm.jar”包冲突。解决办法是移除Spring2.5 AOP Libraries中的“asm-2.2.3.jar”即可 。可是让我头痛的是怎么移除呢?MyEclipse 6.5 上要想单独移除asm-2.2.3 是不可能的,只能连spring 2.5 aop Libraries 一块移除,然后重新添加,这次选择直接添加.jar文件到lib 目录,但是我就怎么呀找到那个选择直接添加.jar文件的窗口选项在哪里,后来没办法只好在发布以后删除发布完成以后tomcat 对应目录下的asm-2.2.3.jar 。第一个问题就这样勉强的解决了。
第二个问题,
java.lang.IllegalArgumentException: Original must not be null
有了这个问题,基本就能确定是spring 不能将对象注入的原因 一般是找不到对应的set 方法,我的错误是没写下面红颜色的set 方法。
package com.cntion.example.action;
import java.util.List;
import com.cntion.example.model.Product;
import com.cntion.example.service.ProductManager;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;
/**
* @author hsmiel
*
*/
public class ProductAction extends ActionSupport {
private ProductManager productManager;
private Product product;
private String queryString;
public ProductManager getProductManager() {
return productManager;
}
public void setProductManager(ProductManager productManager) {
this.productManager = productManager;
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public String getQueryString() {
return queryString;
}
public void setQueryString(String queryString) {
this.queryString = queryString;
}
public String insert(){
productManager.insertProduct(product);
return SUCCESS;
}
public String search(){
List result=productManager.searchProduct(queryString);
ServletActionContext.getRequest().setAttribute("searchresults",result);
return SUCCESS;
}
}
下面是我实现的关键代码
1 每次启动自动生成索引 CompassIndexBuilder.java
package com.cntion.example.service.impl; import org.compass.gps.CompassGps; import org.springframework.beans.factory.InitializingBean; /** * 通过quartz定时调度定时重建索引或自动随Spring ApplicationContext启动而重建索引的Builder. * 会启动后延时数秒新开线程调用compassGps.index()函数. * 默认会在Web应用每次启动时重建索引,可以设置buildIndex属性为false来禁止此功能. * 也可以不用本Builder, 编写手动调用compassGps.index()的代码. * */ public class CompassIndexBuilder implements InitializingBean { // 是否需要建立索引,可被设置为false使本Builder失效. private boolean buildIndex = false; // 索引操作线程延时启动的时间,单位为秒 private int lazyTime = 10; // Compass封装 private CompassGps compassGps; // 索引线程 private Thread indexThread = new Thread() { @Override public void run() { try { Thread.sleep(lazyTime * 1000); System.out.println("begin compass index..."); long beginTime = System.currentTimeMillis(); // 重建索引. // 如果compass实体中定义的索引文件已存在,索引过程中会建立临时索引, // 索引完成后再进行覆盖. compassGps.index(); long costTime = System.currentTimeMillis() - beginTime; System.out.println("compss index finished."); System.out.println("costed " + costTime + " milliseconds"); } catch (InterruptedException e) { e.printStackTrace(); } } }; /** * 实现<code>InitializingBean</code>接口,在完成注入后调用启动索引线程. * * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() */ public void afterPropertiesSet() throws Exception { if (buildIndex) { indexThread.setDaemon(true); indexThread.setName("Compass Indexer"); indexThread.start(); } } public void setBuildIndex(boolean buildIndex) { this.buildIndex = buildIndex; } public void setLazyTime(int lazyTime) { this.lazyTime = lazyTime; } public void setCompassGps(CompassGps compassGps) { this.compassGps = compassGps; } }
2 spring 配置文件 applicationContext.xml
<?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: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-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd" default-lazy-init="true"> <!-- 定义数据源的Bean ,给Hibernate的sessionFactory--> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"> </property> <property name="url" value="jdbc:oracle:thin:@localhost:1521:hsmile"> </property> <property name="username" value="scott"></property> <property name="password" value="tiger"></property> </bean> <!-- 定义Hibernate的sessionFactory,通过该Bean,可以获得Hibernate的Session--> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.Oracle9Dialect </prop> <!--设置二级缓冲--> <prop key="hibernate.cache.provider_class"> org.hibernate.cache.EhCacheProvider </prop> <!--设置二级缓冲,打开查询缓冲--> <prop key="hibernate.cache.use_query_cache">true</prop> <!--设置显示Hibernate操作的SQL语句--> <prop key="hibernate.show_sql">true</prop> </props> </property> <property name="mappingResources"> <list> <value> com/cntion/example/model/Product.hbm.xml </value> </list> </property> </bean> <!-- 注入依赖类 --> <bean id="productDao" class="com.cntion.example.dao.hibernate.ProductDaoHibernate"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="productManager" class="com.cntion.example.service.impl.ProductManagerImpl"> <property name="productDao" ref="productDao"></property> <property name="compassTemplate" ref="compassTemplate"></property> </bean> <bean id="productBean" class="com.cntion.example.action.ProductAction" scope="prototype"> <property name="productManager" ref="productManager"></property> </bean> <!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref local="sessionFactory"/> </property> </bean> <!-- 配置事务特性 ,配置add、delete和update开始的方法,事务传播特性为required--> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="insert*" propagation="REQUIRED"/> <tx:method name="delete*" propagation="REQUIRED"/> <tx:method name="update*" propagation="REQUIRED"/> <tx:method name="*" read-only="true"/> </tx:attributes> </tx:advice> <!-- 配置那些类的方法进行事务管理,当前cn.com.jobedu.oa.service包中的子包、类中所有方法需要,还需要参考tx:advice的设置 --> <aop:config> <aop:pointcut id="allManagerMethod" expression="execution (* com.cntion.example.service.*.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/> </aop:config> </beans>
3 sprint 集成 compass 配置文件 applicationContext-compass.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd" default-lazy-init="true"> <bean id="annotationConfiguration" class="org.compass.annotations.config.CompassAnnotationsConfiguration"> </bean> <!-- org.compass.spring.LocalCompassBean --> <bean id="compass" class="org.compass.spring.LocalCompassBean"> <property name="resourceDirectoryLocations"> <list> <value>classpath:com/cntion</value> </list> </property> <property name="connection"> <value>/lucene/indexes</value> </property> <property name="classMappings"> <list> <value>com.cntion.example.model.Product</value> </list> </property> <property name="compassConfiguration" ref="annotationConfiguration" /> <property name="compassSettings"> <props> <prop key="compass.transaction.factory"> org.compass.spring.transaction.SpringSyncTransactionFactory </prop> <prop key="compass.engine.analyzer.MMAnalyzer.CustomAnalyzer"> net.paoding.analysis.analyzer.PaodingAnalyzer </prop> </props> </property> <property name="transactionManager" ref="transactionManager" /> </bean> <bean id="hibernateGpsDevice" class="org.compass.gps.device.hibernate.HibernateGpsDevice"> <property name="name"> <value>hibernateDevice</value> </property> <property name="sessionFactory" ref="sessionFactory" /> <property name="mirrorDataChanges"> <value>true</value> </property> </bean> <!-- 同步更新索引 --> <bean id="compassGps" class="org.compass.gps.impl.SingleCompassGps" init-method="start" destroy-method="stop"> <property name="compass" ref="compass" /> <property name="gpsDevices"> <list> <bean class="org.compass.spring.device.SpringSyncTransactionGpsDeviceWrapper"> <property name="gpsDevice" ref="hibernateGpsDevice" /> </bean> </list> </property> </bean> <bean id="compassTemplate" class="org.compass.core.CompassTemplate"> <property name="compass" ref="compass" /> </bean> <!-- 定时重建索引(利用quartz)或随Spring ApplicationContext启动而重建索引 --> <bean id="compassIndexBuilder" class="com.cntion.example.service.impl.CompassIndexBuilder" lazy-init="false"> <property name="compassGps" ref="compassGps" /> <property name="buildIndex" value="true" /> <property name="lazyTime" value="10" /> </bean> </beans>
4 struts.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.objectFactory" value="spring" /> <include file="struts-default.xml" /> <package name="product" extends="struts-default" namespace="/product"> <!-- 配置Struts2的Action,class值要与applicationContext*.xml中的id的值一致。 --> <action name="insert" class="productBean" method="insert"> <result>insertOk.jsp</result> </action> <action name="search" class="productBean" method="search"> <result>searchResults.jsp</result> </action> </package> </struts>
5 收索方法 红颜色的地方是表示按照商品名称收索
public List searchProduct(String queryString) {
Compass compass=compassTemplate.getCompass();
CompassSession session=compass.openSession();
CompassHits hits=session.queryBuilder().queryString("name:"+queryString).toQuery().hits();
List list=new ArrayList();
for(int i=0;i<hits.length();i++){
Product hit=(Product)hits.data(i);
list.add(hit);
}
return list;
}
6 实体类
package com.cntion.example.model; import org.compass.annotations.*; /** * Product entity. * * @author MyEclipse Persistence Tools */ @Searchable public class Product implements java.io.Serializable { // Fields @SearchableId private String id; @SearchableProperty(name="name") private String name; @SearchableProperty(name="price") private Double price; @SearchableProperty(name="brand") private String brand; @SearchableProperty(name="description") private String description; // Constructors /** default constructor */ public Product() { } /** full constructor */ public Product(String name, Double price, String brand, String description) { this.name = name; this.price = price; this.brand = brand; this.description = description; } // Property accessors public String getId() { return this.id; } public void setId(String id) { this.id = id; } public String getName() { return this.name; } public void setName(String name) { this.name = name; } public Double getPrice() { return this.price; } public void setPrice(Double price) { this.price = price; } public String getBrand() { return this.brand; } public void setBrand(String brand) { this.brand = brand; } public String getDescription() { return this.description; } public void setDescription(String description) { this.description = description; } }
其中很多地方我还是不太明白。.....继续努力。
评论
视频在哪里呀?
相关推荐
通过以上步骤,你可以在SSH框架下成功集成Compass实现站内搜索分页。这一过程涉及到Java Web开发的多个层面,包括MVC架构、数据库操作、全文检索以及用户体验设计。熟练掌握这些技能将有助于构建高效且功能丰富的Web...
【SSH+Compass搜索引擎简单项目】是一个基于Struts2(S),Hibernate(H)和Spring(S)的Java Web应用程序,结合了Compass搜索引擎库,用于实现对数据库中两个表的高效检索功能。这个项目旨在提供一个清晰易懂的...
5. 实现业务逻辑,可能涉及通过Compass进行搜索,同时利用Hibernate和SSH2进行数据存储和安全控制。 由于没有具体的描述,无法给出更多详细的解决策略。但是,如果你遇到类似的问题,你应该检查配置文件是否正确,...
计算机硬件控制_驱动级键盘鼠标同步_PS2接口UDP协议多机协同_基于rabirdwinio和pynput的跨设备输入共享系统_实现多台Windows电脑的键盘鼠标同步操作_支持
嵌入式八股文面试题库资料知识宝典-TCPIP协议栈.zip
少儿编程scratch项目源代码文件案例素材-开膛手杰克.zip
基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型,个人经导师指导并认可通过的高分设计项目,评审分99分,代码完整确保可以运行,小白也可以亲自搞定,主要针对计算机相关专业的正在做大作业的学生和需要项目实战练习的学习者,可作为毕业设计、课程设计、期末大作业,代码资料完整,下载可用。 基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现
内容概要:本文详细探讨了电力弹簧技术在主动配电网规划及运行优化调度中的应用。首先介绍了电力弹簧技术作为智能电网调控手段的优势,如自适应性强、响应速度快、节能环保等。接着阐述了主动配电网规划的目标和策略,包括优化电网结构、提高能源利用效率和降低故障风险。随后讨论了运行优化调度的原则和方法,强调了实时监测、智能调度策略以及优化调度模型的重要性。最后通过实际案例分析展示了电力弹簧技术在提升电网稳定性、可靠性和能效方面的显著效果,展望了其广阔的应用前景。 适合人群:从事电力系统规划、运行管理的研究人员和技术人员,以及对智能电网感兴趣的学者和学生。 使用场景及目标:适用于希望深入了解电力弹簧技术及其在主动配电网规划和运行优化调度中具体应用的专业人士。目标是掌握电力弹簧技术的工作原理、优势及其在实际项目中的实施方法。 其他说明:本文不仅提供了理论分析,还有具体的案例支持,有助于读者全面理解电力弹簧技术的实际应用价值。
嵌入式八股文面试题库资料知识宝典-C语言思维导图.zip
电路教学与科研案例的结合—以最大功率传输定理为例.pdf
内容概要:本文深入介绍了HarmonyOS文件系统及其在万物互联时代的重要性。HarmonyOS自2019年发布以来,逐步覆盖多种智能设备,构建了庞大的鸿蒙生态。文件系统作为其中的“数字管家”,不仅管理存储资源,还实现多设备间的数据协同。文章详细介绍了常见的文件系统类型,如FAT、NTFS、UFS、EXT3和ReiserFS,各自特点和适用场景。特别强调了HarmonyOS的分布式文件系统(hmdfs),它通过分布式软总线技术,打破了设备界限,实现了跨设备文件的无缝访问。此外,文章对比了HarmonyOS与Android、iOS文件系统的差异,突出了其在架构、跨设备能力和安全性方面的优势。最后,从开发者视角讲解了开发工具、关键API及注意事项,并展望了未来的技术发展趋势和对鸿蒙生态的影响。 适合人群:对操作系统底层技术感兴趣的开发者和技术爱好者,尤其是关注物联网和多设备协同的用户。 使用场景及目标:①理解HarmonyOS文件系统的工作原理及其在多设备协同中的作用;②掌握不同文件系统的特性和应用场景;③学习如何利用HarmonyOS文件系统进行应用开发,提升跨设备协同和数据安全。 阅读建议:本文内容详实,涵盖了从基础概念到高级开发技巧的多个层次,建议读者结合自身需求,重点关注感兴趣的部分,并通过实践加深理解。特别是开发者可参考提供的API示例和开发技巧,尝试构建基于HarmonyOS的应用。
嵌入式八股文面试题库资料知识宝典-海康嵌入式笔试题.zip
内容概要:本文详细介绍了基于瞬时无功功率理论的三电平有源电力滤波器(APF)仿真研究。主要内容涵盖并联型APF的工作原理、三相三电平NPC结构、谐波检测方法(ipiq)、双闭环控制策略(电压外环+电流内环PI控制)以及SVPWM矢量调制技术。仿真结果显示,在APF投入前后,电网电流THD从21.9%降至3.77%,显著提高了电能质量。 适用人群:从事电力系统研究、电力电子技术开发的专业人士,尤其是对有源电力滤波器及其仿真感兴趣的工程师和技术人员。 使用场景及目标:适用于需要解决电力系统中谐波污染和无功补偿问题的研究项目。目标是通过仿真验证APF的有效性和可行性,优化电力系统的电能质量。 其他说明:文中提到的仿真模型涉及多个关键模块,如三相交流电压模块、非线性负载、信号采集模块、LC滤波器模块等,这些模块的设计和协同工作对于实现良好的谐波抑制和无功补偿至关重要。
基于环比增长的销售统计分析——2019年中青杯全国数学建模竞赛C题.pdf
嵌入式八股文面试题库资料知识宝典-linux面试题.zip
嵌入式八股文面试题库资料知识宝典-linux常见面试题.zip
内容概要:本文探讨了小电流接地系统在配电网络中的应用,特别是在单相故障情况下的仿真分析。文中介绍了小电流接地系统的背景和发展现状,重点讨论了两种常见的接地方式——中性点不接地和中性点经消弧线圈接地。利用Matlab作为仿真工具,作者构建了详细的电路模型,模拟了单相故障的发生过程,并通过多个结果图表展示了故障电流、电压波形及系统运行状态。此外,文章还包括了详细的设计说明书和PPT介绍,帮助读者全面理解仿真过程和技术细节。 适合人群:从事电力系统研究、维护的技术人员,尤其是关注配电网络安全和稳定的工程师。 使用场景及目标:适用于希望深入了解小电流接地系统的工作原理和故障处理机制的专业人士。通过本研究,读者可以掌握如何使用Matlab进行电力系统仿真,评估不同接地方式的效果,优化配电网络的安全性能。 其他说明:随文附带完整的仿真工程文件、结果图、设计说明书及PPT介绍,便于读者进一步探索和实践。
少儿编程scratch项目源代码文件案例素材-激烈的殴斗.zip
嵌入式八股文面试题库资料知识宝典-小米嵌入式软件工程师笔试题目解析.zip
内容概要:本文详细探讨了车辆主动避撞技术中的两种常见策略——纵向紧急制动避撞和横向紧急转向避撞。首先介绍了这两种避撞策略的基本概念,接着深入分析了临界纵向安全距离的概念及其对避撞模式选择的影响。文中特别强调了五次多项式换道轨迹模型在计算横向紧急转向避撞安全距离中的应用。最后,通过一个简化的程序实现了避撞策略的模拟和可视化展示,帮助读者更好地理解不同避撞方式的应用场景和技术细节。 适合人群:汽车工程技术人员、交通安全研究人员、自动驾驶开发者。 使用场景及目标:适用于研究和开发车辆主动避撞系统的专业人士,旨在提高对避撞策略的理解,优化避撞算法的设计,提升行车安全性。 其他说明:文章不仅提供了理论分析,还结合了具体的数学模型和程序实现,使读者能够从多个角度全面掌握车辆避撞技术的关键要素。