2015-09-25 42 views
0

我正在做一個Spring項目,我得到這個錯誤,當我想創建一個JDBC模板對象:空數據源

2015-09-25 11:58:46,260 | taskScheduler-6 | | ERROR |  
org.springframework.scheduling.support.TaskUtils$LoggingErrorHandler:95  
|Unexpected error occurred in scheduled task. 
java.lang.IllegalArgumentException: DataSource must not be null 

我宣佈的數據來源是這樣的:

@Inject 
private EnvironmentDataSources envDataSources; 

,我需要做兩個對象,就像這樣:

@Override 
public List<theObjects> getInformation() { 

    NamedParameterJdbcTemplate selectOPR = new NamedParameterJdbcTemplate(
      envDataSources.getDataSource(EnvironmentObject1)); 


    NamedParameterJdbcTemplate selectUTL = new NamedParameterJdbcTemplate(
      envDataSources.getDataSource(EnvironmentObject2)); 

不過,我收到空例外。有人知道爲什麼發生這種情況?

+0

你使用Spring啓動?你在哪裏給jdbc驅動程序,用戶名和密碼? – Kris

+0

這就是EnvironmentObjectParameter1和EnvironmentObjectParameter2(我需要連接的模式和密碼)。數據庫信息位於名爲database.properties的文件中。 – Vito

回答

-1

添加此構造在DAOImpl

@Autowired

公共ServiceDAODataSource(數據源){

super(); 
setDataSource(dataSource); 

}