jspgou商城部署时报错:Could not open Hibernate Session for transaction; nested exception is org.hibernate.ex
1.在使用tomcat部署一些东西时,你会遇到返回码500,比如下面部署jspgou商城报错
type exception report message could not open hibernate session for transaction; nested exception is org.hibernate.exception.genericjdbcexception: could not open connection description the server encountered an unexpected condition that prevented it from fulfilling the request. exception org.springframework.transaction.cannotcreatetransactionexception: could not open hibernate session for transaction; nested exception is org.hibernate.exception.genericjdbcexception: could not open connection org.springframework.orm.hibernate4.hibernatetransactionmanager.dobegin(hibernatetransactionmanager.java:544) org.springframework.transaction.support.abstractplatformtransactionmanager.gettransaction(abstractplatformtransactionmanager.java:373) org.springframework.transaction.interceptor.transactionaspectsupport.createtransactionifnecessary(transactionaspectsupport.java:447) org.springframework.transaction.interceptor.transactionaspectsupport.invokewithintransaction(transactionaspectsupport.java:277) org.springframework.transaction.interceptor.transactioninterceptor.invoke(transactioninterceptor.java:96) org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179) org.springframework.aop.framework.jdkdynamicaopproxy.invoke(jdkdynamicaopproxy.java:213) com.sun.proxy.$proxy30.getwebsite(unknown source) com.jspgou.core.web.websitefilter.dofilter(websitefilter.java:35) org.springframework.orm.hibernate4.support.opensessioninviewfilter.dofilterinternal(opensessioninviewfilter.java:151) org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) org.springframework.web.filter.characterencodingfilter.dofilterinternal(characterencodingfilter.java:197) org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) com.jspgou.common.web.processtimefilter.dofilter(processtimefilter.java:31)
这时候你需要仔细检查一下,有没有和配置文件上面的一一应。 下面用jspgou商城举例:
一、在mysql数据库中创建jspgou数据库(推荐使用此数据库名,否则参照第二条修改对应的数据库链接信息),字符集为utf-8, 二、更改数据库链接,程序包内root\web-inf\config\jdbc.properties文件第20行左右 jdbc.url=jdbc:mysql://127.0.0.1:3306/创建好的数据库名?characterencoding=utf-8 jdbc.username=登录数据库用户名 jdbc.password=登录密码 三、将压缩包内 db文件中jspgou.sql文件导入至创建好的jspgou数据库中,如导入中出现执行sql语句过长问题,请修改 [root@localhost ~]# vim /etc/my.cnf 在[mysqld]下面添加如下列: sql_mode=only_full_group_by,strict_trans_tables,error_for_division_by_zero,no_auto_create_user,no_engine_substitution
[root@localhost ~]# cp -r root/ /data/application/tomcat/webapps/ #因为我已经将目录拷贝到tomcat默认的访问目录下了,所以我们修改的配置文件应该去/data/application/tomcat/webapps/root下面找 [root@localhost ~]# cd /data/application/tomcat/webapps/root/web-inf/config/ [root@localhost config]# vim jdbc.properties
输入你自己的数据库密码,而且你数据库里面库的名字一定要和jdbc.url里面的保持一致jdbc.url=jdbc:mysql://127.0.0.1:3306/创建好的数据库名?characterencoding=utf-8 修改完后保存退出,并重启相应的服务就可以了。 如果重启服务还是显示500的返回码,那就重启虚拟机
[root@localhost ~]# reboot now #重启虚拟机 [root@localhost ~]# systemctl stop firewalld #关闭防火墙 [root@localhost ~]# setenforce 0 #关闭selinux [root@localhost ~]# systemctl restart mysqld #重启数据库 [root@localhost ~]# /data/application/tomcat/bin/startup.sh #启动tomact服务 using catalina_base: /data/application/tomcat using catalina_home: /data/application/tomcat using catalina_tmpdir: /data/application/tomcat/temp using jre_home: /usr/local/java using classpath: /data/application/tomcat/bin/bootstrap.jar:/data/application/tomcat/bin/tomcat-juli.jar tomcat started.
你们的评论和点赞是我写文章的最大动力,蟹蟹。
上一篇: mongodb数据库的6个安全设置命令
下一篇: 部署redis-sentinel的步骤