Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java @申报人未能引入新方法_Java_Spring_Aop - Fatal编程技术网

Java @申报人未能引入新方法

Java @申报人未能引入新方法,java,spring,aop,Java,Spring,Aop,各位,我是春天的初学者,我遇到了一些关于@DeclareParents的问题。我在行动中遵循了《春天》中的指示,但我没有意识到其中的介绍 这是我的密码。 我首先定义接口性能 public interface Performance { void perform(); } 然后实现接口 @Component public class OnePerformance implements Performance { @Autowired public OnePerforman

各位,我是春天的初学者,我遇到了一些关于@DeclareParents的问题。我在行动中遵循了《春天》中的指示,但我没有意识到其中的介绍

这是我的密码。 我首先定义接口性能

public interface Performance {
    void perform();
}
然后实现接口

@Component
public class OnePerformance implements Performance {
    @Autowired
    public OnePerformance(){
    }

    public void perform() {
        System.out.println("The Band is performing....");
    }
}

我想将方法void performancecore()引入性能中。 所以我定义了接口

public interface Encoreable {
    void performEncore();
}
落实,

@Aspect
public class DefaultEncoreable implements Encoreable{
    public void performEncore() {
        System.out.println("performEncore");
    }
}
并介绍,

@Aspect
@Component
public class EncoreableIntroduction {            
    @DeclareParents(value="Performance+",
        , defaultImpl=DefaultEncoreable.class)
     public static Encoreable encoreable;
}
我使用自动配置

@Configuration
@EnableAspectJAutoProxy
@ComponentScan
public class ConcertConfig {
}
但是,在测试时,我没有引入void performancecore()方法

我还启用了AspectJ支持插件。


我仔细阅读了这本书和几篇博客,但仍然找不到原因。那么这个问题的原因可能是什么呢?提前感谢。

感谢M.Deinum、NewUser和Wim Deblauwe。在他们的帮助下,我终于解决了问题。前面的JUnit4类不正确

解决此问题的正确方法是将性能强制转换为可编码,然后调用performancecore()方法

代码如下:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes= ConcertConfig.class)
public class OnePerformanceTest {
    @Autowired
    private Performance performance;

    @Test
    public void perform() throws Exception {
        Encoreable encoreable = (Encoreable)(performance);
        encoreable.performEncore();
    }
}

您是如何进行测试的?jUnits?是的,我正在用JUnit4进行测试。我们可以看看测试类吗?当然可以,非常感谢。在关于测试类的描述中有一个屏幕截图。我在健身房的自动取款机上,但我稍后会发布测试课程。你在Intellij中启用了支持吗?
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes= ConcertConfig.class)
public class OnePerformanceTest {
    @Autowired
    private Performance performance;

    @Test
    public void perform() throws Exception {
        Encoreable encoreable = (Encoreable)(performance);
        encoreable.performEncore();
    }
}