谁能帮我解决这个问题,我正在使用 SQLMap(ibatis) 使用 java。我有 3 个类,即 MainConfiguration、SQLMap、DBUtility。
- 主要配置(该类用于在 SQLMap 类中设置对象)
public class MainConfiguration
{
public static String file = "configuration/db/SQLMapConfig.conf";
public static void main(String[] args) throws Exception
{
new MainConfiguration().loadConfiguration();
}
public static void loadConfiguration()
{
SQLMap.setMapFile(file);
List list = DBUtility.loadUsers();
}
}
- SQL Map(这个类是and对象的getter和setter)
public final class SQLMap
{
private static SqlMapClient sqlMap;
public static void setMapFile(String sMapFile)
{
try
{
sqlMap = SqlMapClientBuilder.buildSqlMapClient(new FileReader(sMapFile));
}
catch (Exception e)
{
throw new RuntimeException("Error initializing SqlMapClient class", e);
}
}
public static SqlMapClient getSqlMapInstance()
{
return sqlMap;
}
}
DBUtility(这个类是对象实例和从 SQLMap 类获取对象的地方)
public class DBUtility { // object utility protected static SqlMapClient sqlMap = SQLMap.getSqlMapInstance(); //constructor public DBUtility() throws Exception { } public static List loadUsers() { //it's working logger.info("SQLMap Get Instance = " + SQLMap.getSqlMapInstance()); //it's not working logger.info("SQLMap Get Instance = " + sqlMap); //code below will be error because of null sqlMap try { listUser = sqlMap.queryForList("getUsers"); } catch (Exception sqle) { logger.error("Error on load all user", sqle); } return listUser; } }
记录器给我这个:
SQLMap 获取实例 = com.ibatis.sqlmap.engine.impl.SqlMapClientImpl@76707e36
SQLMap 获取实例 = null
即使我有实例对象,第二个日志怎么给我null?