The Spring Boot startup class scanned for this service, but the ServiceImpl class reported an AopConfigException error

package com.wansensoft.service.role

import com.wansensoft.entities.role.SysRoleMenuRel
import com.wansensoft.mappers.role.SysRoleMenuRelMapper
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
import org.springframework.stereotype.Service

@Service
class KtSysRoleMenuRelServiceImpl : ServiceImpl<SysRoleMenuRelMapper, SysRoleMenuRel>(), ISysRoleMenuRelService {

    override fun listByRoleId(roleId: Long?): List<SysRoleMenuRel> {
        requireNotNull(roleId) { "roleId must not be null" }

        return lambdaQuery()
                .eq(SysRoleMenuRel::getRoleId, roleId)
                .list()
    }
}

error log

Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class com.wansensoft.service.role.KtSysRoleMenuRelServiceImpl: Common causes of this problem include using a final class or a non-visible class
    at org.springframework.aop.framework.CglibAopProxy.buildProxy(CglibAopProxy.java:222)
    at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:155)
    at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.buildProxy(AbstractAutoProxyCreator.java:517)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:464)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:369)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:318)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:434)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1773)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:598)
    ... 15 common frames omitted
Caused by: java.lang.IllegalArgumentException: Cannot subclass final class com.wansensoft.service.role.KtSysRoleMenuRelServiceImpl
    at org.springframework.cglib.proxy.Enhancer.generateClass(Enhancer.java:653)
    at org.springframework.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:26)
    at org.springframework.cglib.core.ClassLoaderAwareGeneratorStrategy.generate(ClassLoaderAwareGeneratorStrategy.java:57)
    at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:366)
    at org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:575)
    at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.lambda$new$1(AbstractClassGenerator.java:107)
    at org.springframework.cglib.core.internal.LoadingCache.lambda$createEntry$1(LoadingCache.java:52)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
    at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:57)
    at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34)
    at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:130)
    at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:317)
    at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:562)
    at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:407)
    at org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:62)
    at org.springframework.aop.framework.CglibAopProxy.buildProxy(CglibAopProxy.java:213)
    ... 24 common frames omitted

Comment From: mhalbritter

Hello,

your class must not be final, e.g. by adding the open modifier to it.

It feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.