0

I have my Exception base class which is named ApiException. Below is the structure:

@Getter
@NoArgsConstructor
@Component
public class ApiException extends RuntimeException {
  private String code, message;
}


@Component
@Configuration
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "abc")
@Getter
@Slf4j
public class ErrorConfigServiceImpl {

private  Map<String, Error> errors;

      public ErrorConfigServiceImpl(Map<String, Error> errors) {
        this.errors = errors;
      }

      public Error getErrorRepresentation(String errorCode) {
        return new ErrorRepresentation(getRepresentationByCode(errorCode));
      }

}

Here, I have to call getErrorRepresentation(String errorCode) method in my ApiException class. So, I have used the below code to autowire the object. But while doing this I'm getting "Null" on the autowired object. Could someone please assist me on this, Thanks!

@Component
@NoArgsConstructor
@Getter
public class ApiException extends RuntimeException {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    
    @Autowired
    private ErrorConfigServiceImpl errorConfigServiceImpl;
}
swanthri
  • 79
  • 1
  • 7

0 Answers0