簡體   English   中英

Groovy Spring Bean類路徑

[英]Groovy Spring Bean Classpath

我試圖在啟動Web應用程序時運行Groovy腳本。 我首先嘗試遵循《春季食譜》一書中的示例。

我在以下軟件包中有一個SimpleInterestCalculator- com.apress.springrecipes.interest

bean程序包位於com.wer.com程序包的src/test/resources中,這就是bean所在的位置。

我的輸入是

<lang:groovy id="interestCalculator" script-source="classpath:com/apress/springrecipes/interest/SimpleInterestCalculator.groovy">
  <lang:property name="rateCalculator" value="rateCalculator" />
</lang:groovy>

我收到以下錯誤。

Caused by: org.springframework.beans.factory.BeanCreationException:
  Error creating bean with name 'simpleInterestCalculator':
  Could not determine scripted object type for GroovyScriptFactory:
    script source locator [classpath:src/com/apress/springrecipes/interest/SimpleInterestCalculator.groovy];
  nested exception is java.io.FileNotFoundException:
    class path resource [src/com/apress/springrecipes/interest/SimpleInterestCalculator.groovy] cannot be opened because it does not exist

您收到的錯誤是FileNotFoundException。 這意味着它沒有找到腳本文件本身。 如果文件存在,則在運行時它可能不在類路徑中。

在您的IDE中檢查bin / out目錄,以查看.groovy文件是否存在。 有時,如果您在源目錄中包含.groovy,則您的IDE會假定這是“源”代碼並將其編譯為字節碼。 結果是您最終將在類路徑上獲得一個.class文件,而不是常規腳本本身。 這將因設置和所使用的IDE而異。 如果這似乎是問題所在,則可能有一個選項,或者您可以使用編譯器不會選擇的替代擴展。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM