我得到異常:無會話發現當前線程,當我想通過休眠數據庫連接,我的CFG文件: 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"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Here we blog web application</display-name>
<servlet>
<servlet-name>web-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>web-dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/web-dispatcher-servlet.xml</param-value>
</context-param>
</web-app>
調度的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>
我想一個解決方案(在方法連接到冬眠增加在服務層@Transactional註釋,但現在我得到2個例外: 無法打開Hibernate的Session的事務;嵌套的例外是org.hibernate作爲.exc eption.GenericJDBCException:無法打開連接,任何解決方案? - 也許問題與此相關:Cannot load JDBC driver class 'com.postgresql.jdbc.Driver' - 沒有人能夠幫助我,我都neccesary的依賴,但不知道什麼是錯的,感謝
我完全不明白我應該怎麼做,下載JAR和請你解釋我如何將它添加到類路徑?但我忘了寫,我使用maven,我有正確的依賴關係,如果你看這張圖片http://screenshot.cz/6YJM4/,你可以看到我在我的外部庫(和在.jar是所需的驅動程序類) –
嗯。它是否添加到你的pom.xml中?在這種情況下,它應該在你的classpath上。什麼是堆棧跟蹤? – Lexandro
是的,我有正確的依賴關係,我敢肯定,堆棧跟蹤第一種情況:http://screenshot.cz/UT91N/,第二種:http://screenshot.cz/AHH0Z/,可能是爲了警告,因爲驅動程序未加載,所以im絕望:/ –