-
关于spring 4.0.0+hibernate 4.3.6的整合0
总报一个错误,实在看不到是哪的问题,求教一下:十月 13, 2014 9:36:54 上午 org.hibernate.engine.internal.StatisticalLoggingSessionEventListener end INFO: Session Metrics { 0 nanoseconds spent acquiring 0 JDBC connections; 0 nanoseconds spent releasing 0 JDBC connections; 0 nanoseconds spent preparing 0 JDBC statements; 0 nanoseconds spent executing 0 JDBC statements; 0 nanoseconds spent executing 0 JDBC batches; 0 nanoseconds spent performing 0 L2C puts; 0 nanoseconds spent performing 0 L2C hits; 0 nanoseconds spent performing 0 L2C misses; 0 nanoseconds spent executing 0 flushes (flushing a total of 0 entities and 0 collections); 0 nanoseconds spent executing 0 partial-flushes (flushing a total of 0 entities and 0 collections) } Pre-handle Hibernate: select * from ( select row_.*, rownum rownum_ from ( from Project where fzrbh='001' order by qyrq asc ) row_ where rownum <= ?) where rownum_ > ? java.lang.UnsupportedOperationException: Not supported by BasicDataSource at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:899) at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:139) at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:380) at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:228) at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:171) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.connection(StatementPreparerImpl.java:63) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:162) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:186) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:160) at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1884) at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1861) at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1838) at org.hibernate.loader.Loader.doQuery(Loader.java:909) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354) at org.hibernate.loader.Loader.doList(Loader.java:2553) at org.hibernate.loader.Loader.doList(Loader.java:2539) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2369) at org.hibernate.loader.Loader.list(Loader.java:2364) at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:353) at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1873) at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:311) at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:141) at com.szht.raising.dao.RaisingDAOHibernateImpl.getRaisingList(RaisingDAOHibernateImpl.java:46) at com.szht.raising.controller.RaisingController.getRaisingList(RaisingController.java:45) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:175) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:931) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:833) at javax.servlet.http.HttpServlet.service(HttpServlet.java:646) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:807) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) 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.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:149) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108) 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:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2442) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2431) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)
以下是我写的配置
web.xml<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext-*.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <filter> <filter-name>opensessioninview</filter-name> <filter-class> org.springframework.orm.hibernate4.support.OpenSessionInViewFilter </filter-class> </filter> <servlet> <servlet-name>springController</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <filter-mapping> <filter-name>opensessioninview</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <servlet-mapping> <servlet-name>springController</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> </web-app>
applicationContext-componet.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:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> <!-- 开启组件扫描 --> <bean id="mydataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" > <property name="url" value="jdbc:oracle:thin:@192.168.100.205:1521:orcl"> </property> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"> </property> <property name="username" value="byjjh2"> </property> <property name="password" value="byjjh2"> </property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <!-- 注入连接参数 --> <property name="dataSource" ref="mydataSource"> </property> <!-- 注入hibernate配置参数 --> <property name="hibernateProperties"> <props> <!-- <prop key="current_session_context_class">thread</prop> --> <prop key="hibernate.dialect"> org.hibernate.dialect.Oracle10gDialect </prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> </props> </property> <!-- 设置加载的hbm.xml --> <property name="mappingResources"> <list> <value>com/szht/entity/Project.hbm.xml</value> </list> </property> </bean> </beans>
applicationContext-transaction.xml<!-- Spring声明式事务管理 --> <!-- 定义hibernate事务管理Bean --> <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <!-- 开启事务注解配置 --> <tx:annotation-driven proxy-target-class="true" transaction-manager="txManager"/> </beans>
applicationContext-mvc.xml<!-- 开启组件扫描 --> <context:component-scan base-package="com.szht"/> <!-- 登录拦截器 --> <bean id="loginInterceptor" class="com.szht.interceptor.LoginInterceptor"></bean> <!-- 注解请求映射 --> <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"> <property name="interceptors"> <list> <ref bean="loginInterceptor"/> </list> </property> </bean> <bean id="handler" class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="messageConverters"> <list> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/html; charset=UTF-8</value> <value>application/json;charset=UTF-8</value> </list> </property> </bean> <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/html; charset=UTF-8</value> <value>application/json;charset=UTF-8</value> </list> </property> </bean> </list> </property> </bean> <!-- 定义视图解析器,解析Controller返回的信息 --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="suffix" value=".jsp"></property> <property name="prefix" value="/WEB-INF/jsp/"></property> </bean>
BaseDAOpackage com.szht.base; import javax.annotation.Resource; import org.hibernate.Session; import org.hibernate.SessionFactory; public class HibernateBaseDAO { private SessionFactory sessionFactory; @Resource public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } /** * 获得当前事物的session * * @return org.hibernate.Session */ public Session getCurrentSession() { return sessionFactory.getCurrentSession(); } }
HibernateDAO实现类
package com.szht.raising.dao; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.hibernate.Query; import org.springframework.stereotype.Repository; import com.szht.base.HibernateBaseDAO; import com.szht.entity.Project; @Repository public class RaisingDAOHibernateImpl extends HibernateBaseDAO implements RaisingDAO{ @Override public Map<String, Object> getRaisingList( final Map<String, String> queryConditionMap, final int pageNumber, final int pageSize, final String sort, final String order, final String username) throws Exception { final Map<String,Object> map =new HashMap<String,Object>(); final List<String> para = new ArrayList<String>(); try { final StringBuffer hql = new StringBuffer("from Project where fzrbh='"+username+"' "); String condition = queryConditionMap.get("condition"); if(condition!=null&&!"".equals(condition)){ hql.append(" and ( xmmc like ? or xyjzje like ? or qyrq like ? or xmflmc like ? or issp like ? or bmmc like ?)"); para.add("%"+condition+"%"); para.add("%"+condition+"%"); para.add("%"+condition+"%"); para.add("%"+condition+"%"); para.add("%"+condition+"%"); para.add("%"+condition+"%"); } //排序 hql.append(" order by "+sort+" "+order+"" ); //记录 Query query = getCurrentSession().createSQLQuery(hql.toString()); int start = (pageNumber-1)*pageSize+1; query.setFirstResult(start); query.setMaxResults(pageSize); for(int i=0;i<para.size();i++){ query.setParameter(i, para.get(i)); } List<Project> list = query.list(); map.put("rows", list); final String countHql = "select count(*) from ("+hql.toString()+")"; for(int i=0;i<para.size();i++){ query.setParameter(i, para.get(i)); } int total = (int)getCurrentSession().createSQLQuery(countHql).uniqueResult(); map.put("total", total); } catch (Exception ex) { ex.printStackTrace(); } return map; } }
2014年10月13日 10:12
4个答案 按时间排序 按投票排序
-
可以把classpath:applicationContext-mvc.xml放在servelet中加载,
<servlet>
<servlet-name>springController</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext-mvc.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
剩下的放在context-param加载:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext-xxx.xml,
classpath:applicationContext-yyy.xml,
classpath:applicationContext-zzz.xml,
</param-value>
</context-param>
这样试试,看行不行2014年10月13日 15:49
-
web.xml 中:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-*.xml</param-value> </context-param>
<servlet>
<servlet-name>springController</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
这两段代码中,applicationContext-mvc.xml会加载2次,会不会是这个问题。2014年10月13日 15:44
相关推荐
SSH整合是Java Web开发中常见的技术栈,由Struts2、Spring和Hibernate三个框架组成,分别负责表现层、业务逻辑层和数据持久化层。这个压缩包提供的版本是Struts2.3.16、Spring4.0.0和Hibernate4.2.8,这是一套相对...
《Leap Motion开发者套件4.0.0+52173:开启手势识别与Unity3D集成的新篇章》 Leap Motion是一款先进的手势控制技术,它通过高精度的传感器捕捉用户的手部动作,将这些动作转化为计算机可识别的指令,为用户提供了一...
本整合源码提供了Struts2.3.7、Spring3.0.0和Hibernate4.0.0的集成示例,帮助开发者理解如何在实际项目中将这三个框架无缝连接。 Struts2是基于Action和拦截器的MVC框架,它通过配置文件或注解定义Action与URL的...
Struts2.3.15.2、Spring4.0.0和Hibernate4.2.6是Java开发中三大主流框架的特定版本,它们的整合是企业级应用开发中的常见实践,以实现高效的MVC(Model-View-Controller)架构。SSH即Struts2、Spring和Hibernate的...
1、Struts2.3.15+Spring4.0.0+hibernate4.2.3整合 2、拦截器实现用户权限检查功能 3、拦截器自动生成日志 4、未登录非法访问页面检测 5、三种方式日志的生成 6、页面访问计数 7、选中页面对应的帮助页面实现 8、根据...
1、Struts2.3.15+Spring4.0.0+hibernate4.2.3整合 2、拦截器实现用户权限检查功能 3、拦截器自动生成日志 4、未登录非法访问页面检测 5、三种方式日志的生成 6、页面访问计数 7、选中页面对应的帮助页面实现 ...
整体来说,这个教程是一个非常有价值的学习资源,不仅为初学者提供了一个搭建SSH框架项目的实例,也为想要深入学习和研究Struts2、Spring和Hibernate整合的开发者提供了参考。通过这个教程,开发者可以掌握如何在...
3. **重新打包与签名**:完成修改后,apktool可以将所有修改整合并重新打包成一个新的APK,最后还可以进行签名,使其能够在设备上安装运行。 ShakaApktool与apktool之间的关系密切,ShakaApktool是在apktool基础上...
含有 SSH整合(Spring4+Struts2+Hibernate4)所需的包,包括spring-jdbc-4.0.0.RELEASE.jar,struts2-dojo-plugin-2.3.15.1.jar,hibernate-commons-annotations-4.0.4.Final,spring-jdbc-4.0.0.RELEASE.jar等等,...
windows + opencv-4.0.0 + contrib-4.0.0编译库 debug与release版本 这个是我在做windows 下 SLAM使用的opencv库 使用vs2022编译可以正常使用,感谢那些给予我帮助的大佬
spring 4.0.0 框架核心包 aopalliance-1.0.jar spring-aop-4.0.0.RELEASE.jar spring-beans-4.0.0.RELEASE.jar spring-context-4.0.0.RELEASE.jar spring-core-4.0.0.RELEASE.jar spring-expression-4.0.0....
本教程中提到的开发环境包括Windows 8 64位操作系统,Eclipse Indigo Service Release 2版本,Tomcat 7.0服务器,Struts *.*.*.*版本,Spring Framework 3.2.3.RELEASE版本,以及Hibernate Release 4.0.0.CR6版本。...
这个源码包"struts2.3.7-spring3.1.0-hibernate4.0.0 整合源码"提供了一个完整的示例,展示了如何将这三个框架协同工作,实现MVC(模型-视图-控制器)架构和持久化层的高效管理。 Struts2是Apache软件基金会下的一...
4. **数据访问抽象**:Spring提供了对各种数据源(如JDBC、ORM框架如Hibernate、MyBatis等)的抽象,简化了数据库操作。Spring Data项目进一步增强了数据访问能力,提供了自动化的CRUD操作和Repository接口。 5. **...
### Spring 4.0.0.RELEASE 版本整合包介绍 #### 一、Spring框架简介 Spring框架是由Rod Johnson创建的一个开源项目,最初是为了简化Java企业级应用程序开发而设计的。Spring框架提供了完整的轻量级开发解决方案,...
SmartDraw v2010 4.0.0.part1
《深入理解ShakaApktool 4.0.0与apktool 2.3.2:解析Android应用的利器》 在Android应用开发和逆向工程领域,ShakaApktool和apktool是两个非常重要的工具,它们为开发者提供了深入洞察APK文件结构的能力。...
学习Spring 4.0.0,你需要掌握的核心概念有:依赖注入(Dependency Injection),面向切面编程(Aspect-Oriented Programming),Spring MVC用于构建Web应用,以及如何使用Spring进行数据库操作,如JdbcTemplate和...