当我使 DAO 可序列化时,我有 DAO 我得到异常:
Cannot serialize session attribute com.sun.faces.renderkit.ServerSideStateHelper.LogicalViewMap for session C354B1B6053088CBB8E8A933E5F8EAE0
java.io.NotSerializableException: org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper
我的道:
public boolean getConnection() {
try {
InitialContext context = new InitialContext();
DataSource dataSource = (DataSource) context.lookup("java:/comp/env/jdbc/Orcl");
connection = dataSource.getConnection();
return true;
} catch (SQLException ex) {
Logger.getLogger(KPIDAO.class.getName()).log(Level.SEVERE, null, ex);
return false;
} catch (NamingException ex) {
Logger.getLogger(KPIDAO.class.getName()).log(Level.SEVERE, null, ex);
return false;
}
}
在控制器 (@ViewScoped) 中:
KPIDAO kpiDAO = new KPIDAO();
上下文.xml
<Resource
name="jdbc/Orcl"
auth="Container"
type="javax.sql.DataSource"
username="username"
password="password"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@192.168.1.10:1521:XE"
maxActive="8"
/>
什么是正确的解决方案?