6
我使用guice-servlet(2.0)在每個HTTP請求的開始處注入數據庫連接,但是如何才能找出請求何時結束以便我可以關閉連接?清理@RequestScoped對象?
的web.xml
<filter>
<filter-name>Guice Filter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Guice Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
GuiceServletContextListener
/**
* Creates a new Database connection.
*/
@RequestScoped
@Provides
private Connection getConnection();