确实好久没有写过了,一直以来把写博文当作自己学习的总结,当作做过的笔记,随时都可以拿出来看看。不过最近习惯了用OneNote和印象笔记,所以就很少在论坛写博文。但是偶尔看到几篇被转载了,也小小的虚荣了下。这种虚荣大神们已经习以为常,他们是不能理解的。
好吧,转入正题。
参加工作从事Java Web开发将近两年,也没有完整的搭建出一个SSH框架的项目,说出来确实有点不好意思,并且前一段一个朋友问我搭建过SSH框架没,我都没有好意思说没有。所以才有了搭建一个SSH框架项目的想法,因此有了今天的这篇博文。
,但是Spring框架中的代码Session session = (entityInterceptor != null ? sessionFactory.openSession(entityInterceptor) : sessionFactory.openSession())显示用到该方法,虽然调用这段代码的方法传进来的entityInterceptor就为null。。。网上搜索无果,所以最终在整合Spring的时候使用Hibernate-3.6.10.Final。详细错误信息见本目录下6),MySQL 5.5.28下的project数据库。操作完成后的结构如图所示:
操作完成后的结构如图所示:
操作完成后的结构如图所示:
BaseDao.java
本来想创建Struts2 + Spring3 + Hibernate4的项目,结果行动之后才发现版本之间不兼容的现象挺严重(我自己是这么认为的,如果有大神看出来是我开发中出的问题导致麻烦告知下),不得不把Hibernate4换成Hibernate3。因为中间换框架,所以导致此博文中整合Hibernate部分是否会报错,不过最终的项目是可以执行的。我会把项目打包上传到csdn资源上。可以点击这里下载。
SPRING官方网站改版后,下载spring非常麻烦,下给出官方直接下载路径:
http://repo.springsource.org/libs-release-local/org/springframework/spring/
Spring Framework 4.0.0下载
http://repo.springsource.org/libs-release-local/org/springframework/spring/4.0.0.RELEASE/spring-framework-4.0.0.RELEASE-dist.zip
spring 3.2.x(Spring Framework 3.2.6)下载:
http://repo.springsource.org/libs-release-local/org/springframework/spring/3.2.4.RELEASE/spring-framework-3.2.4.RELEASE-dist.zip
http://repo.springsource.org/libs-release-local/org/springframework/spring/3.2.5.RELEASE/spring-framework-3.2.5.RELEASE-dist.zip
http://repo.springsource.org/libs-release-local/org/springframework/spring/3.2.6.RELEASE/spring-framework-3.2.6.RELEASE-dist.zip
1、配置struts时,主要是jsp和action的操作控制,根据struts.xml里的配置,决定action转向哪个页面
2、整合Hibernate时,我第一次用的是最新的5.x,里边少一个类org.hibernate.service.ServiceRegistry,然后下载来一个4.x版本的;Hibernate.cfg.xml主要时数据库的配置(
3、在整合spring3.x时,首先出现:找不到这个类“org.apache.commons.logging.LogFactory”,把commons-logging.jar这个包添加上去之后又出现:java.lang.NoClassDefFoundError: com/mchange/v2/ser/Indirector,这个错,
但是我里边有这个jra包,后来又添加了“mchange-commons-”这个包后,出现【1、首先的报错如下:
严重: Could not open template
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'queryaction' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception isorg.springframework.beans.NotWritablePropertyException: Invalid property 'recordService' of bean class [com.action.QueryMobileAction]: Bean property 'recordService' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1423)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1128)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:314)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1117)
at com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance(SpringObjectFactory.java:221)
at org.apache.struts2.components.ServletUrlRenderer.renderFormUrl(ServletUrlRenderer.java:161)
at org.apache.struts2.components.Form.populateComponentHtmlId(Form.java:220)
at org.apache.struts2.components.UIBean.evaluateParams(UIBean.java:784)
at org.apache.struts2.components.ClosingUIBean.start(ClosingUIBean.java:57)
at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:53)
at org.apache.jsp.jsp.iframes.IVR.IVR_005fmytd_jsp._jspx_meth_s_005fform_005f0(IVR_005fmytd_jsp.java:138)
at org.apache.jsp.jsp.iframes.IVR.IVR_005fmytd_jsp._jspService(IVR_005fmytd_jsp.java:102)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2522)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2511)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'recordService' of bean class [com.action.QueryMobileAction]: Bean property 'recordService' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1042)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:902)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:57)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1420)
... 44 more