2016-11-16 7 views
1

SQLクエリを読み込むためにproperties.getProperty( "")メソッドを使用しようとしています。しかし、常にnullを返します。私はそれぞれの質疑応答を行ってきましたが、実際に必要なものや、間違っていたものが見つかりませんでした。 次のように私の.xmlの設定ファイルは次のとおりです。properties.getProperty( "queryLocation")はnullを返します

<bean id="baseDao" class="com.ems.BaseDao.BaseDao" abstract="true"> 
    <property name="properties" ref="queryPros"/> 
</bean> 

<bean id="queryPros" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> 
    <property name="ignoreResourceNotFound" value="true"/> 
    <property name="singleton" value="true"/> 
    <property name="locations"> 
     <list> 
      <value>classpath*:/com/ems/mssqlFile/HomeDao.mssql.sql</value> 
      <value>classpath*:/com/ems/mssqlFile/ListDao.mssql</value> 
      //both cases problem 
     </list> 
    </property> 
</bean> 

マイダオクラスとしては、以下:

public abstract class BaseDao { 
     protected Properties properties; 
     public void setProperties(Properties properties) { 
     this.properties = properties; 
      } 
     } 
public class HomeDao extends BaseDao implements IHomeDao { 
    public List<HomeDto> getListFormTable() throws SQLException { 
    String query = properties.getProperty("ListDao.getListFormTable"); 
    org.hibernate.Query hQuery = hibernateQuery(query); 
    List<HomeDto> homeDtoList= hQuery.list(); 
    return homeDtoList; 
    } 
} 
+0

あなたはうれしくプロパティを含んでいません。 –

+0

@ M.Deinum、ここに私のプロパティです: 'public abstract class BaseDao { protectedプロパティのプロパティ; public void setProperties(プロパティのプロパティ){ this.properties = properties; } } ' –

+0

私はプロパティファイルの内容を意味します。コメントとして追加しないで、質問を編集してください。 –

答えて

0

最後に、私は私の答え自分自身を得ました。それはファイルの場所のエラーでした。だから、次は、正しいファイルの場所です:

<bean id="queryPros" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> 
<property name="ignoreResourceNotFound" value="true"/> 
<property name="singleton" value="true"/> 
<property name="locations"> 
    <list> 
     // if file extension specific 
     <value>classpath*:/META-INF/mssqlFile/*.sql</value> 

     // if file specific 
     <value>classpath*:/META-INF/mssqlFile/HomeDao.mssql.sql</value> 
     <value>classpath*:/META-INF/mssqlFile/ListDao.mssql</value> 

    </list> 
</property> 

重要!ファイルはMETA-INFフォルダに保存する必要があります

+0

私はまた、リソースフォルダにファイルを保持し、正常に動作します。 META-INFフォルダもリソースフォルダにあります。 –

関連する問題