mtim
Mar 3rd, 2008, 09:21 AM
Hi all,
can't instantiate spring container in groovy script if I run that script within ant task in maven's pom.xml.
Spring finds configuration xml file but it seems that it doesn't see any beans defined. Here debugging messages that spring logs:
INFO ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlAp plicationContext@666d83: display name [org.springf
ramework.context.support.ClassPathXmlApplicationCo ntext@666d83]; startup date [Mon Mar 03 09:57:13 EST 2008]; root of context hierarchy
DEBUG PluggableSchemaResolver - Loading schema mappings from [META-INF/spring.schemas]
DEBUG PluggableSchemaResolver - Loaded schema mappings: {}
DEBUG PluggableSchemaResolver - Loading schema mappings from [META-INF/spring.schemas]
DEBUG PluggableSchemaResolver - Loaded schema mappings: {}
DEBUG XmlBeanDefinitionReader - Loaded 0 bean definitions from location pattern [classpath*:applicationContext.xml]
INFO ClassPathXmlApplicationContext - Bean factory for application context [org.springframework.context.support.ClassPathXmlAp plicationContext@666d83
]: org.springframework.beans.factory.support.DefaultL istableBeanFactory@1e5cf0
DEBUG ClassPathXmlApplicationContext - 0 beans defined in org.springframework.context.support.ClassPathXmlAp plicationContext@666d83: display name [org
.springframework.context.support.ClassPathXmlAppli cationContext@666d83]; startup date [Mon Mar 03 09:57:13 EST 2008]; root of context hierarchy
DEBUG ClassPathXmlApplicationContext - Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.De
legatingMessageSource@aecb09]
DEBUG ClassPathXmlApplicationContext - Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.spring
framework.context.event.SimpleApplicationEventMult icaster@721965]
INFO DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@1e5cf0: defini
ng beans []; root of factory hierarchy
DEBUG ClassPathXmlApplicationContext - Publishing event in context [org.springframework.context.support.ClassPathXmlAp plicationContext@666d83]: org.sp
ringframework.context.event.ContextRefreshedEvent[source=org.springframework.context.support.ClassPa thXmlApplicationContext@666d83: display name [org.
springframework.context.support.ClassPathXmlApplic ationContext@666d83]; startup date [Mon Mar 03 09:57:13 EST 2008]; root of context hierarchy]
2 problems here :
=====> XmlBeanDefinitionReader loads/finds 0 beans.
and
=========> Loading schema mappings from [META-INF/spring.schemas]
=========> Loaded schema mappings: {}
If I wrap groovy script into GroovyTestCase and run it as test case using maven's surefile plugin it works fine.
Has anyone noticed this ? Any ideas why this is happening ?
spring config:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<bean id="messageSource" class="org.springframework.context.support.ResourceBundle MessageSource">
<property name="basename" value="messages"/>
</bean>
<bean id="countryService" class="org.springframework.samples.countries.DefaultCount ryService"/>
</beans>
groovy script:
import org.springframework.context.support.ClassPathXmlAp plicationContext
import org.springframework.samples.countries.CountryServi ce
class ScriptRunner {
static void main(args) {
println '*'*60 + '\n\t\tRUNNING GROOVY SCRIPT \n' + '*'*60
def context = new ClassPathXmlApplicationContext("classpath*:applicationContext.xml")
def service = (CountryService) context.getBean("countryService")
def countries = service.getAllCountries(Locale.ENGLISH)
println "Number of countries (GROOVY):: ${countries.size()}"
}
}
pom.xml :
......
<dependency>
<groupId>org.codehaus.mojo.groovy.runtime</groupId>
<artifactId>groovy-runtime-1.1</artifactId>
<version>1.0-beta-3</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>1.5.4</version>
</dependency>
......
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo.groovy</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<configuration>
<tasks>
<taskdef name="groovy"
classname="org.codehaus.groovy.ant.Groovy">
<classpath refid="maven.runtime.classpath"/>
</taskdef>
<groovy src="src/test/groovy/com/test/ScriptRunner.groovy"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Thanks,
Timour
can't instantiate spring container in groovy script if I run that script within ant task in maven's pom.xml.
Spring finds configuration xml file but it seems that it doesn't see any beans defined. Here debugging messages that spring logs:
INFO ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlAp plicationContext@666d83: display name [org.springf
ramework.context.support.ClassPathXmlApplicationCo ntext@666d83]; startup date [Mon Mar 03 09:57:13 EST 2008]; root of context hierarchy
DEBUG PluggableSchemaResolver - Loading schema mappings from [META-INF/spring.schemas]
DEBUG PluggableSchemaResolver - Loaded schema mappings: {}
DEBUG PluggableSchemaResolver - Loading schema mappings from [META-INF/spring.schemas]
DEBUG PluggableSchemaResolver - Loaded schema mappings: {}
DEBUG XmlBeanDefinitionReader - Loaded 0 bean definitions from location pattern [classpath*:applicationContext.xml]
INFO ClassPathXmlApplicationContext - Bean factory for application context [org.springframework.context.support.ClassPathXmlAp plicationContext@666d83
]: org.springframework.beans.factory.support.DefaultL istableBeanFactory@1e5cf0
DEBUG ClassPathXmlApplicationContext - 0 beans defined in org.springframework.context.support.ClassPathXmlAp plicationContext@666d83: display name [org
.springframework.context.support.ClassPathXmlAppli cationContext@666d83]; startup date [Mon Mar 03 09:57:13 EST 2008]; root of context hierarchy
DEBUG ClassPathXmlApplicationContext - Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.De
legatingMessageSource@aecb09]
DEBUG ClassPathXmlApplicationContext - Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.spring
framework.context.event.SimpleApplicationEventMult icaster@721965]
INFO DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@1e5cf0: defini
ng beans []; root of factory hierarchy
DEBUG ClassPathXmlApplicationContext - Publishing event in context [org.springframework.context.support.ClassPathXmlAp plicationContext@666d83]: org.sp
ringframework.context.event.ContextRefreshedEvent[source=org.springframework.context.support.ClassPa thXmlApplicationContext@666d83: display name [org.
springframework.context.support.ClassPathXmlApplic ationContext@666d83]; startup date [Mon Mar 03 09:57:13 EST 2008]; root of context hierarchy]
2 problems here :
=====> XmlBeanDefinitionReader loads/finds 0 beans.
and
=========> Loading schema mappings from [META-INF/spring.schemas]
=========> Loaded schema mappings: {}
If I wrap groovy script into GroovyTestCase and run it as test case using maven's surefile plugin it works fine.
Has anyone noticed this ? Any ideas why this is happening ?
spring config:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<bean id="messageSource" class="org.springframework.context.support.ResourceBundle MessageSource">
<property name="basename" value="messages"/>
</bean>
<bean id="countryService" class="org.springframework.samples.countries.DefaultCount ryService"/>
</beans>
groovy script:
import org.springframework.context.support.ClassPathXmlAp plicationContext
import org.springframework.samples.countries.CountryServi ce
class ScriptRunner {
static void main(args) {
println '*'*60 + '\n\t\tRUNNING GROOVY SCRIPT \n' + '*'*60
def context = new ClassPathXmlApplicationContext("classpath*:applicationContext.xml")
def service = (CountryService) context.getBean("countryService")
def countries = service.getAllCountries(Locale.ENGLISH)
println "Number of countries (GROOVY):: ${countries.size()}"
}
}
pom.xml :
......
<dependency>
<groupId>org.codehaus.mojo.groovy.runtime</groupId>
<artifactId>groovy-runtime-1.1</artifactId>
<version>1.0-beta-3</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>1.5.4</version>
</dependency>
......
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo.groovy</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<configuration>
<tasks>
<taskdef name="groovy"
classname="org.codehaus.groovy.ant.Groovy">
<classpath refid="maven.runtime.classpath"/>
</taskdef>
<groovy src="src/test/groovy/com/test/ScriptRunner.groovy"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Thanks,
Timour