java - Groovy,jruby 作为 Spring beans
问题描述
我正在尝试将 groovy 类作为 bean 注入,但遇到java.io.FileNotFoundException
异常。
WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'coconut' defined in class path resource [aspects.xml]: Cannot resolve reference to bean 'lime' while setting bean property 'lime'; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'lime': BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'lime': Could not determine scripted object type for GroovyScriptFactory: script source locator [classpath:band.Lime.groovyy]; nested exception is java.io.FileNotFoundException: class path resource [band.Lime.groovy] cannot be opened because it does not exist
我的 Groovy 文件 - Lime.groovy
:
class Lime implements band.Lime{
void drink(){
print "You drink Lime!"}
}
我的pom.xml
文件:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<properties></properties>
<groupId>com.gmail@qwertygoog</groupId>
<artifactId>RockWithAspects</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.2.5.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.5.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.5</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>3.0.0</version>
<type>pom</type>
</dependency>
</dependencies>
</project>
那么,有什么建议吗?
upd.-这里是椰子类
public class Coconut {
private Lime lime;
public Coconut() {
}
public void drinkFast(){
System.out.println("You drink coconut ...");
lime.drink();
}
@Autowired
public void setLime(Lime lime) {
this.lime = lime;
}
}
我的 XML 就像:
<?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-3.0.xsd
http://www.springframework.org/schema/lang
http://www.springframework.org/schema/lang/spring-lang.xsd
"
>
<bean id="coconut" class="band.Coconut">
<!-- <property name="lime" ref="lime"/>-->
</bean>
<lang:groovy id="lime"
script-source="classpath:Lime.groovy"
/>
</beans>
解决方案
推荐阅读
- java - 是否可以在不使用模拟框架的情况下测试方法是否被调用
- c# - 如何从 zkteco 获取用户照片?
- ios - IOS键盘在网络输入时随机消失
- python - 不从自定义视图/表单将 **kwargs 传递给 django-import-export 资源
- tensorflow - Tensorflow,Keras:如何解决“Dimension must be equal, but are ...”一般错误
- python - Pandas - 如何组合来自文本文件的多个数据框并保存到每个输出文件
- python - Flask Sql-Alchemy,sqlalchemy.exc.OperationalError:(psycopg2.OperationalError)致命:用户“abc”的 PAM 身份验证失败
- python-3.x - 正则表达式检查字符串中是否存在一个或多个特殊字符
- c++ - 如何将变量初始化为附加到播放器的相机组件的指针
- python - 当列不为空时,pandas to_excel 问题给出索引空错误