Problem with Spring + Groovy
Hi,
I am using Springsource Tool Suite 2.6.0.M2, apache-maven-3.0.2.
I followed the "Spring and Scripting" article at http://groovy.dzone.com/articles/spr...=0&refr esh=0
When running the application I got "org.springframework.beans.factory.BeanCreationExc eption: Error creating bean with name 'helloWorldService': Could not determine scripted object type for GroovyScriptFactory"
:(
Do I missing something? Thanks in advance!
My pom.xml list:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.springandgroovy</groupId>
<artifactId>springandgroovy</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>springandgroovy</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.0.5.RELEASE</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.5.RELEASE</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>3.0.5.RELEASE</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.5.RELEASE</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>1.1-rc-1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
My beans.xml list:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...ring-beans.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd">
<lang:groovy id="helloWorldService"
script-source="classpath:com/springandgroovy/HelloWorldServiceImp.groovy">
<lang:property name="name" value="meera" />
</lang:groovy>
</beans>
The app output:
Mar 1, 2011 3:30:32 PM org.springframework.context.support.AbstractApplic ationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlAp plicationContext@1c1ea29: startup date [Tue Mar 01 15:30:32 CST 2011]; root of context hierarchy
Mar 1, 2011 3:30:32 PM org.springframework.beans.factory.xml.XmlBeanDefin itionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [beans.xml]
Mar 1, 2011 3:30:32 PM org.springframework.beans.factory.support.DefaultL istableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@f42ad0: defining beans [org.springframework.scripting.config.scriptFactory PostProcessor,helloWorldService]; root of factory hierarchy
Mar 1, 2011 3:30:32 PM org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@f42ad0: defining beans [org.springframework.scripting.config.scriptFactory PostProcessor,helloWorldService]; root of factory hierarchy
Mar 1, 2011 3:30:32 PM org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@17431b9: defining beans [scriptFactory.helloWorldService,scriptedObject.hel loWorldService]; parent: org.springframework.beans.factory.support.DefaultL istableBeanFactory@f42ad0
Exception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'helloWorldService': BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'helloWorldService': Could not determine scripted object type for GroovyScriptFactory: script source locator [classpath:com/springandgroovy/HelloWorldServiceImp.groovy]; nested exception is java.io.FileNotFoundException: class path resource [com/springandgroovy/HelloWorldServiceImp.groovy] cannot be opened because it does not exist
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:452)
at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 91)
at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:288 )
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:895)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:425)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:139)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:83)
at com.springandgroovy.App.main(App.java:14)
Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'helloWorldService': Could not determine scripted object type for GroovyScriptFactory: script source locator [classpath:com/springandgroovy/HelloWorldServiceImp.groovy]; nested exception is java.io.FileNotFoundException: class path resource [com/springandgroovy/HelloWorldServiceImp.groovy] cannot be opened because it does not exist
at org.springframework.scripting.support.ScriptFactor yPostProcessor.postProcessBeforeInstantiation(Scri ptFactoryPostProcessor.java:297)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyBeanPostProcessors BeforeInstantiation(AbstractAutowireCapableBeanFac tory.java:848)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.resolveBeforeInstantiat ion(AbstractAutowireCapableBeanFactory.java:820)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:446)
... 10 more
Caused by: java.io.FileNotFoundException: class path resource [com/springandgroovy/HelloWorldServiceImp.groovy] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getI nputStream(ClassPathResource.java:158)
at org.springframework.scripting.support.ResourceScri ptSource.getScriptAsString(ResourceScriptSource.ja va:82)
at org.springframework.scripting.groovy.GroovyScriptF actory.getScriptedObjectType(GroovyScriptFactory.j ava:201)
at org.springframework.scripting.support.ScriptFactor yPostProcessor.postProcessBeforeInstantiation(Scri ptFactoryPostProcessor.java:290)
... 13 more