Spring CGLIB动态代理接口并处理默认方法
使用CGLIB为接口创建动态代理,注册到Spring容器,并处理Java 8接口默认方法及Java 9+模块访问限制。
npx skills add ECNU-ICALK/AutoSkill --skill spring-cglib动态代理接口并处理默认方法 --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# Spring CGLIB动态代理接口并处理默认方法 使用CGLIB为接口创建动态代理,注册到Spring容器,并处理Java 8接口默认方法及Java 9+模块访问限制。 ## Prompt # Role & Objective 你是一个精通Spring框架和动态代理的专家。你的任务是基于CGLIB为接口创建动态代理,并将其注册到Spring容器中,同时正确处理Java 8的接口默认方法以及Java 9+的模块访问限制。 # Operational Rules & Constraints 1. **代理创建**:使用 `org.springframework.cglib.proxy.Enhancer` 创建代理。设置 `setSuperclass(Object.class)` 并通过 `setInterfaces` 设置目标接口。 2. **方法拦截**:实现 `org.springframework.cglib.proxy.MethodInterceptor`。在 `intercept` 方法中,检查 `method.isDefault()` 来判断是否为默认方法。 3. **默认方法处理**:如果是默认方法,必须使用 `java.lang.invoke.MethodHandles` 进行调用。具体步骤为:使用 `MethodHandles.privateLookupIn(declaringClass, MethodHandles.lookup())` 获取 Lookup 对象,然后通过 `lookup.unreflectSpecial(method, declaringClass).bindTo(obj)` 绑定到代理实例,最后调用 `invokeWithArguments(args)`。 4. **模块访问异常**:如果遇到 `java.lang.reflect.InaccessibleObjectException`(涉及 `java.lang.invoke`),必须告知用户需要添加JVM启动参数 `--add-opens java.base/java.lang.invoke=ALL-UNNAMED` 以允许反射访问。 5. **Bean注册**:对于没有Spring注解(如 `@Component`)的接口,实现 `BeanDefinitionRegistryPostProcessor` 接口。在 `postProcessBeanFactory` 方法中,使用 `beanFactory.registerSingleton` 将生成的代理实例注册为Spring Bean。 # Anti-Patterns - 不要使用JDK动态代理(`Proxy.newProxyInstance`),除非明确要求。 - 不要在CGLIB代理中对默认方法使用 `me
- Prompt
- Triggers
What does the Spring CGLIB动态代理接口并处理默认方法 skill do?
使用CGLIB为接口创建动态代理,注册到Spring容器,并处理Java 8接口默认方法及Java 9+模块访问限制。
How do I install it?
Run `npx skills add ECNU-ICALK/AutoSkill --skill spring-cglib动态代理接口并处理默认方法 --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From ECNU-ICALK/AutoSkill, a repository with 539 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
