Java SpringBoot2:测试运行期间AspectJ的问题

Java SpringBoot2:测试运行期间AspectJ的问题,java,spring-boot,mocking,aop,aspectj,Java,Spring Boot,Mocking,Aop,Aspectj,我有一个小AspectJ类的项目: package com.blabla.joy.aspect; import org.aspectj.lang.annotation.Aspect; import org.springframework.stereotype.Component; @Aspect @Component public class SomeAspect { public SomeAspect() { } } 还有一个小测试类: package com.blab

我有一个小AspectJ类的项目:

package com.blabla.joy.aspect;

import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class SomeAspect {
    public SomeAspect() {

    }
}
还有一个小测试类:

package com.blabla.joy.aspect;

import com.blabla.joy.MainSpringBoot;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
@ContextConfiguration(classes = {MainSpringBoot.class})
public class SomeTest {

    @MockBean
    private SomeAspect someAspect;

    @Test
    public void someTest(){
        //test something
    }
}
主要应用程序类别为:

package com.blabla.joy;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

@SpringBootApplication(exclude = MultipartAutoConfiguration.class)
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class MainSpringBoot implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(MainSpringBoot.class, args);
    }

    @Override
    public void run(String... arg0) throws Exception {
        System.out.println("i'm running!!!");
    }
}
当我运行某个测试时,出现以下错误:

java.lang.IllegalStateException: Failed to load ApplicationContext
...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mainSpringBoot': BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: [com.blabla.joy.aspect.SomeAspect$MockitoMock$2005048991] cannot extend concrete aspect [com.blabla.joy.aspect.SomeAspect]
...
Caused by: org.springframework.aop.framework.AopConfigException: [com.blabla.joy.aspect.SomeAspect$MockitoMock$2005048991] cannot extend concrete aspect [com.blabla.joy.aspect.SomeAspect]
...
这是什么意思?我应该在方面、测试或主类中添加一些特殊的逻辑(注释等)

注意:我在项目中使用SpringBoot2

试试这个:

@RunWith(SpringRunner.class)
@SpringBootTest
@ContextConfiguration(classes = {MainSpringBoot.class})
public class SomeTest {

    @Autowired
    @InjectMocks
    private SomeAspect someAspect;

    @Before
    public void init(){
        MockitoAnnotations.initMocks(this)
    }

    @Test
    public void someTest(){
        //test something
    }
}

非常感谢您的回答,但是您能澄清一下@MockBean有什么问题吗?