2012-07-16 20 views
5

使用Grails 2.0.4。在製作電子郵件時,我使用了絕對路徑的很多圖片。每一個都會導致一個惱人的日誌條目。有一個簡單的解決方法嗎?它們確實存在,似乎資源插件不喜歡絕對路徑。這也發生在localhost/dev環境之外。以絕對方式使用圖像時的Grails資源警告日誌條目:true

<img src="${resource(dir: 'images/brochure', file: 'arrow_up.png', absolute: 'true')}" alt="Up" /> 

結果

WARN resource.ResourceTagLib - Invocation of <r:resource> for a resource that apparently doesn't exist: http://localhost:8080/images/brochure/arrow_up.png 
+0

我也遇到這個使用Grails 2.3.4。你有沒有找到解決方案? – rcgeorge23 2014-02-01 10:07:22

+0

我向Grails JIRA提交了一個問題:http://jira.grails.org/browse/GPRESOURCES-256 – Klemens 2014-04-28 11:02:05

+0

我找到了一個解決方案,請參閱我自己的回答 – Peter 2014-05-07 00:57:21

回答

3

與Grails 2.1.x及更高版本(包括最新的2.3.x)一起工作的解決方案是將這些條目添加到Config.groovy的log4j配置塊中 - 無需其他代碼更改。

log4j = { 
      //your other stuff ... 
      error 'grails.app.services.org.grails.plugin.resource' 
      error 'grails.app.taglib.org.grails.plugin.resource' 
      error 'grails.app.resourceMappers.org.grails.plugin.resource' 
} 
-1

uou使用 'Grails的資源' 插件。它也標記'資源'。嘗試使用直接的G-標籤:

<img src="${g.resource(dir: 'images/brochure', file: 'arrow_up.png', absolute: 'true')}" alt="Up" /> 

,或者使用R-標籤從資源插件(推薦):

<img src="${r.resource(uri: 'images/brochure/arrow_up.png')}" /> 

獲取更多信息here

+0

這些都只是委託給資源插件 – Peter 2012-07-18 05:07:36

+1

沒有。我用命名空間來直接定義。如果安裝了資源插件,'資源'標籤默認與'r'命名空間關聯。 – jenk 2012-07-18 07:10:54

0

我知道這是一個老問題,但它似乎仍然是Grails 2.3.x的一個問題。有一個在ResourceTagLib寫着resource關閉上述評論:

@todo目前這不會爲絕對=「真」調用工作,它應該只是直通這些

爲了去除在日誌中的警告,我推翻了resource關閉,改變該位:

... 
if (!info.debug && log.warnEnabled) { 
    log.warn "Invocation of <r:resource> for a resource that apparently doesn't exist: ${info.uri}" 
} 
... 

這樣:

... 
if (attrs.absolute != true && !info.debug && log.warnEnabled) { 
    log.warn "Invocation of <r:resource> for a resource that apparently doesn't exist: ${info.uri}" 
} 
... 
+2

你能解釋一下你做了這個改變嗎? – nuoritoveri 2014-05-05 13:56:50

0

它似乎只發生在使用dir參數時嘗試使用子目錄。您需要指定uri。我假設dir只能是單層目錄。

你可以嘗試以下的(從plugin docs):

<r:img uri="images/logo.png" width="100" height="50"/>