我想将托管bean拆分成几个文件,因为源代码重复了几次。
这是我想要放入外部文件的外部Java方法:
public class CalcWeight implements Serializable
{
// Call the Oracle JDBC Connection driver as service
@Resource(name = "jdbc/Oracle")
// Data source
private DataSource ds;
public float TotalDCWeightCalc(int dcId) throws SQLException
{
float DCWeight = 0;
if (ds == null)
{
throw new SQLException("Can't get data source");
}
........... SQL query
return DCWeight;
}
}
我使用此代码调用外部Java方法:
@ViewScoped
public class DCProfileTabGeneral implements Serializable
{
// Call the Oracle JDBC Connection driver as service
@Resource(name = "jdbc/Oracle")
// Data source
private DataSource ds;
// Weight initialization
private CalcWeight weight;
// Power initialization
private CalcPower power;
// Cooling initialization
private CalcCooling cooling;
// Constructor
public DCProfileTabGeneral()
{
// Weight initialization
weight = new CalcWeight();
}
..........................
weight.TotalDCWeightCalc(id)
.....................
}
运行此代码时收到此错误消息:
java.sql.SQLException: Can't get data source
我如何解决这个问题?