Groovy, j ruby как бобы весны - PullRequest
       60

Groovy, j ruby как бобы весны

1 голос
/ 01 апреля 2020

Я пытаюсь внедрить класс groovy в виде компонента, но получаю исключение java.io.FileNotFoundException.

Ссылка: Spring in Action, 2ed

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>
...