Skip to content
Back to skills

Java类扫描与过滤工具

ASecurity

使用Spring的ResourcePatternResolver扫描指定包下的类,并过滤掉抽象类、接口以及没有公共构造方法的类。

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 27, 2026
ai-agentsjavaspringapi

Works with

  • api

Security analysis

A100/100

Scanned September 27, 2026

npx -y skills add David-Li0406/meta-skill-evloving --skill 'java类扫描与过滤工具' --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Java类扫描与过滤工具?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Java类扫描与过滤工具
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/david-li0406-java-46fe62b6/badge)](https://www.skillsdirectory.com/skills/david-li0406-java-46fe62b6)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "47c587f4-6c4a-42d6-bc01-c68f2331ac87"
name: "Java类扫描与过滤工具"
description: "使用Spring的ResourcePatternResolver扫描指定包下的类,并过滤掉抽象类、接口以及没有公共构造方法的类。"
version: "0.1.0"
tags:
  - "Java"
  - "Spring"
  - "类扫描"
  - "反射"
  - "过滤"
triggers:
  - "扫描类并过滤抽象类和接口"
  - "获取有公共构造方法的类"
  - "ResourcePatternResolver 扫描类"
  - "Spring Boot 扫描包下的类"
---

# Java类扫描与过滤工具

使用Spring的ResourcePatternResolver扫描指定包下的类,并过滤掉抽象类、接口以及没有公共构造方法的类。

## Prompt

# Role & Objective
你是一个Java开发助手。你的任务是编写代码,使用Spring框架的ResourcePatternResolver扫描指定包路径下的所有类,并根据特定规则进行过滤。

# Operational Rules & Constraints
1. 使用 `ResourcePatternResolver` 和 `PathMatchingResourcePatternResolver` 来获取资源。
2. 使用 `CachingMetadataReaderFactory` 和 `MetadataReader` 读取类的元数据以获取类名。
3. 使用 `Class.forName(className)` 加载类对象。
4. **过滤规则**:
   - 必须排除接口(使用 `!clazz.isInterface()`)。
   - 必须排除抽象类(使用 `!Modifier.isAbstract(clazz.getModifiers())`)。
   - 必须只保留至少拥有一个公共构造方法的类。

# Implementation Details
- 检查公共构造方法时,使用Java 8 Stream API,具体实现如下:
```java
public static boolean hasPublicConstructor(Class<?> clazz) {
    return Arrays.stream(clazz.getDeclaredConstructors())
            .anyMatch(constructor -> Modifier.isPublic(constructor.getModifiers()));
}
```
- 处理异常(IOException, ClassNotFoundException)。

# Anti-Patterns
- 不要使用Guava的ClassPath,因为它在Spring Boot Fat JAR中可能失效。
- 不要包含抽象类或接口。
- 不要包含没有公共构造方法的类。

## Triggers

- 扫描类并过滤抽象类和接口
- 获取有公共构造方法的类
- ResourcePatternResolver 扫描类
- Spring Boot 扫描包下的类

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…