我已經從戰爭外部化了配置文件,我想知道如何解決我被迫在應用上下文中提供的絕對位置以使其工作。外部化應用上下文和戰爭hibernate.properties
在我的web.xml我有這個 -
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>file:C:/Program%20Files/somedirectory/webappContext.xml</param-value>
</context-param>
C:/Program%20Files/somedirectory/webappContext.xml具有如下條目:
<import resource="applicationContext-persistence.xml" />
應用程序上下文 - 持久性。 xml和webAppContext.xml存在於同一個目錄下,它有一行 -
<util:properties id="hibernateProperties" location="hibernate.properties" />
<encryption:encryptable-property-placeholder encryptor="stringEncryptor" location="hibernate.properties"/>
Tomcat is unab以找到位於同一目錄中的hibernate.properties文件。相反,它迫使我將其定義如下:
<util:properties id="hibernateProperties" location="file:C:/Program%20Files/somedirectory/hibernate.properties" />
<encryption:encryptable-property-placeholder encryptor="stringEncryptor" location="file:C:/Program%20Files/somedirectory/hibernate.properties"/>
有沒有辦法避開指定完整路徑?爲什麼webAppContext.xml中的行可行,而不是applicationcontext-persistence.xml中的行?兩者在性質上與引用位於同一目錄中的文件類似。
儘管他們可能出現的是類似的,他們都沒有。你可以嘗試用'。/'加前綴,但我懷疑這是否有效。 –
試過。不起作用。 'file:./','./'無效。和絕對'classpath:hibernate.properties'將無法正常工作,因爲程序文件/ somedirectory不在tomcat容器的類路徑中 – sethu