我正在尝试将Groovy类添加到现有的Spring Java项目中。我一直在遵循两个不同来源的指示[1]和[2]然而,它似乎对我不起作用。
这是我的Groovy类:
package com.example.service;
class MessageService {
String message
}
这是我的bean定义:
<?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/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/lang
http://www.springframework.org/schema/lang/spring-lang-2.5.xsd"
>
<lang:groovy id="messenger" script-source="classpath:com.example.service.MessageService.groovy">
<lang:property name="message" value="This is a Groovy message" />
</lang:groovy>
</beans>
我已将文章中描述的依赖项添加到我的pom.xml
:
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.1.8</version>
</dependency>
并更新了我的插件:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<compilerId>groovy-eclipse-compiler</compilerId>
<!-- <verbose>false</verbose> -->
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.8.0-01</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>2.1.8-01</version>
</dependency>
</dependencies>
</plugin>
</plugins>
然而,当我运行mvn test
时,我可以看到Groovy编译器启动并且所有代码“似乎”正确编译,但是当测试运行时,它会进入一些似乎是循环尝试的循环多次开始测试而不会产生精确的错误。
我的定义中有什么不正确吗?
[1] http://docs.spring.io/spring/docs/2.5.3/reference/dynamic-language.html [2] http://groovy.codehaus.org/Groovy-Eclipse+compiler+plugin+for+Maven#Groovy-EclipsecompilerpluginforMaven-WhyanotherGroovycompilerforMavenWhataboutGMaven