Spring boot @ExceptionHandler不在服务类中工作

Spring boot @ExceptionHandler不在服务类中工作,spring-boot,exception,exceptionhandler,Spring Boot,Exception,Exceptionhandler,下面是一个服务类 @Service class Test { public Object findEmployees1(String id, String dbId) { return employeeRepo.findByDatabaseIdAndIdentifier(dbId, id); } public Object findEmployees2(String name, String dbId) { Objec

下面是一个服务类

@Service
class Test {

    public Object findEmployees1(String id, String dbId) {
        return employeeRepo.findByDatabaseIdAndIdentifier(dbId, id);

    }
    
        public Object findEmployees2(String name, String dbId) {
        Object records = employeeRepo.findByNameAndDatabaseId(name, dbId);

    }
    
    
        @ExceptionHandler(Exception.class)
        public void internalErrorExceptionHandler(Exception ex) {
        LOGGER.error("Log the exception here");
        throw new InternalErrorException(ex.getMessage());
    }
}

我想知道,如果类测试中的任何方法中出现任何异常(例如某些SQLException),它会被
@ExceptionHandler
捕获并记录在那里并重新抛出


我不能将
@ExceptionHandler
@ControllerAdvice
一起使用,因为我没有任何带有@Controller注释的类。我写的只是一个从数据库获取数据的通用模块


当我执行代码时,
@ExceptionHandler
下的日志不会被打印,因为它从未被调用过。
如果任何异常出现在任何服务类方法中,而每个方法中都没有单独的try-catch语句,则需要记录并重新显示一个公共异常。

@ExceptionHandler
是一个仅用于web的注释,否则将不起作用。@M.Deinum-是否有其他方法在服务类中实现相同的功能?使用AOP为此。