Java 会话问题(休眠)
我遇到异常:找不到当前线程的会话,当我想通过hibernate连接数据库时,我的cfg文件: web.xml:Java 会话问题(休眠),java,spring,hibernate,postgresql,Java,Spring,Hibernate,Postgresql,我遇到异常:找不到当前线程的会话,当我想通过hibernate连接数据库时,我的cfg文件: web.xml: 在这里,我们介绍一个博客web应用程序 网络调度器 org.springframework.web.servlet.DispatcherServlet 1. 网络调度器 *.htm 上下文配置位置 /WEB-INF/WEB-dispatcher-servlet.xml 调度程序servlet: <?xml version="1.0" encoding="UTF-8"?>
在这里,我们介绍一个博客web应用程序
网络调度器
org.springframework.web.servlet.DispatcherServlet
1.
网络调度器
*.htm
上下文配置位置
/WEB-INF/WEB-dispatcher-servlet.xml
调度程序servlet:
<?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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<mvc:annotation-driven />
<context:component-scan base-package="com.lime"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.postgresql.jdbc.Driver"/>
<property name="url" value="jdbc:postgresql://localhost:8080/come_to_blog_db"/>
<property name="username" value="postgres"/>
<property name="password" value="admin"/>
</bean>
<bean id="mySessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource"/>
<property name="packagesToScan">
<array>
<value>com.lime</value>
</array>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.PostgreSQL9Dialect
</value>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="mySessionFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
-没有人能帮助我,我有所有必要的依赖项,但不知道出了什么问题,谢谢你无法连接,因为驱动程序不在类路径上。
您可以从此处下载:
它可以解决您的jdbc类加载问题。确保您已经将SessionFactorybean连接到dao实现类中。
一种方法如下:
@Resource
private SessionFactory mySessionFactory;
我不太明白我应该怎么做,下载jar,你能解释一下如何将它添加到类路径中吗?但是我忘了写,我使用的是maven,我有正确的依赖关系,如果你看这张图片-,你可以看到我在我的外部库中有jar(在.jar中是必需的驱动程序类),嗯。它是否添加到了pom.xml中?在这种情况下,它应该位于类路径上。stacktrace是什么?是的,我有正确的依赖关系,我确信,第一种情况下的stack trace:,第二种情况下的stack trace:,很可能是为了警告,因为驱动程序没有加载,我很失望:/@CharlieHarper JDBC驱动程序的类名通常是org.postgresql.Driver
,而不是com.postgresql.JDBC.Driver
。通过使用任何zip工具查看jar来验证它。我想查看启动日志stacktrace,而不是请求的stacktrace
@Resource
private SessionFactory mySessionFactory;