0

I'm building a webapp for uploading content. At the moment, I'm using a properties file where I define some variables containing the path to some folders where I want the files to be stored. These paths refer to folders in my file system.

P1: Since I want to make my app more portable, I decided to store my uploaded contents in some folder inside the project classpath but the path I use in the placeholder is not working.

#path.images=C:/uploads/images    

#path.images=classpath:/webapp/uploads/images     (NOT working)

Q1: If it's possible, I would like to know if I'm storing the content in the right place (inside webapp directory).

NOTE: I'm making these changes also because I'm trying to replace the FileInputStream with the getResourceAsStream().

Any help will be much appreciated.

4

2 に答える 2

3

いいえ; アプリケーションと共にデプロイされていないアセットは、別の場所に保存する必要があります。

通常、このようなアセットは構成可能な外部ディレクトリに属します。構成メカニズムには、JNDI、コンテキスト/init パラメータ、環境変数、またはシステム変数が含まれます。

アセットを Web アプリケーション内に保持することは、複数の理由からお勧めできません。最大の理由は次のとおりです。

  1. アプリが war ファイルとしてデプロイされている場合、とにかく war ファイルに書き込むことはできません。
  2. アセットは展開メカニズムに翻弄され、上書きされる可能性があります。

それらを既知の適切な場所に保管し、それらをストリームバックするか、コンテナーを介してアクセスを構成するか、さまざまな CDN メカニズムのいずれかを使用してアクセスを提供します。

于 2013-01-29T14:30:10.673 に答える
0

クラスパスにデータを保存することはできません-読み取り専用です。

移植性を最大限に高めるために、ファイルシステムにデータを保存することはまったく控えてください (たとえば、クラスタリングのシナリオでは、ファイルシステムがすべてのノードで同じであることを確認する必要があります)。

于 2013-01-29T14:32:47.197 に答える