2

I have integrated groovy in my application using spring. My context looks like:

<lang:groovy id="myConfiguration"
                 script-source="classpath:MyGroovy.groovy"
                 refresh-check-delay="1000"/>

MyGroovy is an implementation of MyInterface. I was wondering how can I add more files in my classpath (also implementing the same interface) and to have more beans like the one above dynamically?

I would like to get something like:

<lang:groovy id="myConfiguration"
                 script-source="classpath:*.groovy"
                 refresh-check-delay="1000"/>

And later be able to use a list of implementations of MyInterface and sent it to another bean where I can go through the list and do stuff. My bean would like like:

<bean id="myProcessor"
          class="com.package.processor.MyProcessor">
        <constructor-arg>
            <list value-type="com.package.processor.MyInterface">
                <bean class="MyGroovy1"/>
                <bean class="MyGroovy2"/>
                <bean class="MyGroovy3"/>
            </list>
        </constructor-arg>
</bean>

Is this possible at all? I have just changed the first part and I already get Exceptions and haven't found in the documentation anything related to this topic.

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

Blanca Hdez
  • 3,513
  • 19
  • 71
  • 93
  • The [spring-integration tag](http://stackoverflow.com/tags/spring-integration/info) is for the Spring Integration project not generic "integration with Spring" questions. – Gary Russell May 22 '15 at 13:04
  • I'm really not sure what are You trying to do, but i think You can try to create "myProcessor" bean with list of groovy files(filepaths) and load them inside init-method(). If You would write what is Your goal in it, what are You trying to achive by doing so, maybe i could help some more. Check out this class : "org.springframework.core.io.ClassPathResource" – Fincio May 22 '15 at 13:06
  • If I use your approach, then I wouldn't use the lang:groovy tag, which allows me to have objects implementing MyInterface. What I am trying to do is to create those implementations dynamically when, matching all the files found by the regex *.groovy – Blanca Hdez May 26 '15 at 12:09

0 Answers0