I have a spring based java application with some useful components. As part of the system, I have a groovy script to process some reports. I would like to name the spring component from a groovy script. When I write in Java, I need to use annotation @Autowiredinside @Component, i.e.
@Component
class Reporter{
@Autowired
SearchService searchService;
void report(){
searchService.search(...);
...
}
}
How can I do the same from groovy? First, how can I define @Componentfor integer script? The following code:
@Component class Holder{
@Autowired
SearchService searchService;
def run(){
searchService.search("test");
}
}
new Holder().run()
does not work with NPE on searchService. I am running groovyscripts with GroovyClassloaderinstalled with Java, if that matters. Thank you very much in advance!
source
share