解決org.hibernate.exception.GenericJDBCException: Cannot open connection

dncommander發表於2010-12-22
使用SSH開發專案時發現多次從後臺取資料時就會報org.hibernate.exception.GenericJDBCException: Cannot open connection錯誤,解決辦法如下:在web.xml中配置配置OpenSessionInViewFilter,將如下程式碼加入到web.xml中
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<!-- singleSession預設為true,若設為false則等於沒用OpenSessionInView -->
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<!--Spring Context listener-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext-*.xml</param-value>
</context-param>

問題結決。

相關文章