I have a filter service whose methods are profiled through the aspect. As an example I will give you a piece of code where I have a problem
@Service public class FilterService extends AbstractService { private static final Logger log = LoggerFactory.getLogger(FilterService.class); @Autowired //Proxy to profiling class private FilterService self; private final ItemsRepository itemsRepository; private final Map<String, EnumFilter> enumFilters; public FilterService(ReadWriteLock readWriteLock, ItemsRepository itemsRepository, CategoryRepository categoryRepository, ItemsMapper itemsMapper, CharacteristicsRepository characteristicsRepository, List<EnumFilter> enumFilters) { super(readWriteLock.readLock()); this.itemsRepository = itemsRepository; this.enumFilters = enumFilters.stream().collect(Collectors.toMap(EnumFilter::getId, y -> y)); } @Profileable public ItemsViewShared filterItems(@Nullable String categoryId, @NotNull Set<String> ids, @NotNull Lang lang, @NotNull SortType sortType, @NotNull FilterInfo filterInfo) { try { this.readLock.lock(); final ItemsViewShared itemsViewResponse = new ItemsViewShared(); //in this line inspector show this = FilterService List<Filter> allFilters = self.initNonSpecificFilters(lang, filterInfo); //problem is here //some code... @Profileable private List<Filter> initNonSpecificFilters(@NotNull Lang lang, @NotNull FilterInfo filterInfo) { final List<NumericFilter> allNumericNonSpecific = NumericFilter.getAllNonSpecific(lang, filterInfo); //in this line enumFilters - null final List<EnumOptionFilter> allEnumNonSpecific = enumFilters.values().stream() .flatMap(x -> x.getAllOptions(lang, filterInfo).stream()) .collect(Collectors.toList()); As i know, by default, If the class does not inherit the interface with at least one method, the CGlib proxy will be used and Cglib works through inheritance.
The problem is this: when I call the filterItems method from the controller, the debugger shows in this method that this - FilterService.
Further in this method another method of this class which too should be profiled is caused. In order for the proxy to work, I need self autowired. After that I called my method via self.initNonSpecificFilters and in the debugger I already see that this - FilterService$$EnhancerBySpringCGLIB and all my variables in my class is null, so I get null pointer exception.
Why so, if CGLIb seems to work through inheritance? And why in the first method(filterItems) this - was a class without CGlib, but when you call from it another method (filterItems -> initNotSpecificFilters), cglib already appears.