开发者

Groovy Spring Bean Classpath

开发者 https://www.devze.com 2023-02-14 06:44 出处:网络
I am attempting to run a groovy script on startup for a web application. I am first trying to follow an example from the book Spring Recipes.

I am attempting to run a groovy script on startup for a web application. I am first trying to follow an example from the book Spring Recipes.

I have a SimpleInterestCalculator in the following package - com.apress.springrecipes.interest

The beans package is in src/test/resources in a package com.wer.com, and that's where the bean is.

My entry in that is

<lang:groovy id="interestCalculator" script-source="classpath:com/apress/springrecipes/interest/SimpleInterestCalculator.groovy">
  <lang:property name="rateCalculator" value="rateCalculator" />
</lang:groovy&开发者_如何学Pythongt;

I am getting the following error.

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


The error you are getting is a FileNotFoundException. This means it is not finding the script file itself. If the file is present, then it may not be on the classpath at runtime.

Check your bin/out directory in your IDE to see if the .groovy file is present there. Sometimes if you have a .groovy in a source directory, your IDE assumes this is 'source' code and compiles it down to bytecode. The result is you would end up with a .class file on the classpath instead of the groovy script itself. This will vary with settings and what IDE you are using. If this seems to be the problem there may be an option for this or you can use an alternate extension that will not be picked up by the compiler.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号