Hi,
I'm trying to use dependency injection on annotated fields in Groovy. My proof-of-concept works in the IDE (Intellij IDEA) but not from the shell (bash). I get a NoSuchBeanDefinitionException regarding project. Any suggestions?
Snippets...
build.sh:
Code:
#!/bin/bash
DIR=`dirname $0`
CP=$DIR/alt
CP=$CP:$DIR/lib-alt/ant/ant-launcher-1.7.1.jar
CP=$CP:$DIR/lib-alt/ant/ant-1.7.1.jar
CP=$CP:$DIR/lib/spring/spring.jar
CP=$CP:$DIR/lib/spring/commons-logging.jar
# the groovy way
#groovy -cp $CP $DIR/alt/build/Main.groovy $1
# the java way
CP=$CP:$DIR/lib/groovy-all-1.6.0.jar
java -cp $CP groovy.lang.GroovyShell $DIR/alt/build/Main.groovy $1
spring-config.xml:
Code:
...
<context:component-scan base-package="build"/>
<bean class="groovy.util.AntBuilder" scope="singleton"/>
...
Main.groovy:
Code:
...
def springConfig = new ClassPathXmlApplicationContext("spring-config.xml");
springConfig.refresh()
// def ctx = new GenericApplicationContext(springConfig)
// def ctx = new GenericApplicationContext()
// new ClassPathBeanDefinitionScanner(ctx).scan('build')
// ctx.refresh()
// def p = ctx.getBean("project");
def p = springConfig.getBean("project");
p."$target"()
Project.groovy:
Code:
...
@Component ("project")
public class Project {
@Autowired
AntBuilder ant
...
More info:
- Someone had a similar problem (t=57487) 10 months ago but no response
- Full project at http://subversion.assembla.com/svn/punchy_boy_groovy-build/trunk/
- The project is all about trying to create a refactorable, easily understood build script (only early stages though)
Thanks in Advance,
Pete