How to exclude Aspect from Springboot Unit Test

use springBootTest for unit test. The unit test code is as follows. @ SpringBootTest annotation scans all components, including @ Aspect annotated components. Note / / 1 is a service and performs database operations

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class CheckCardFormatTest{
   @Autowired
   private XxxServiceImpl xxxService; // service layer 
   ....
   @Test
    public void testMainCardFormat() {
        String result=xxxService.query("someParam");// 1.
         ....
    }
   ....
}

the following is the aop code that intercepts all database operations. Note / 2 there is to get the HttpServletRequest, if it works properly in a normal HTTP request. But there is no null pointer exception in the unit test, so I want to @ SpringbootTest annotation scan to eliminate aop, how to solve it?

@Aspect
@Component
public class AbcAspect {
  @Around(value = "execution(*com.xx.preparedStatement_execute(..))")
  public Object druidIntercept(ProceedingJoinPoint pjp) throws Throwable {
  ....
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) requestAttributes;
    HttpServletRequest request = servletRequestAttributes.getRequest();// 2.
  ....
}
Feb.28,2021

has found a solution to exclude a component: annotate @ TestComponent on the class name, and the unit test will Filter the class without scanning.


@ Profile you deserve

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf35f0-46401.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf35f0-46401.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?