Spring Boot自动注册JavaFX FXML为多例Bean
用于在Spring Boot应用中自动扫描指定路径下的FXML文件,解析其fx:controller属性,并将每个FXML视图注册为Spring容器中的Prototype(多例)Bean。解决在BeanDefinitionRegistryPostProcessor阶段无法注入配置Bean的生命周期问题。
npx skills add ECNU-ICALK/AutoSkill --skill spring-boot自动注册javafx-fxml为多例bean --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 Boot自动注册JavaFX FXML为多例Bean 用于在Spring Boot应用中自动扫描指定路径下的FXML文件,解析其fx:controller属性,并将每个FXML视图注册为Spring容器中的Prototype(多例)Bean。解决在BeanDefinitionRegistryPostProcessor阶段无法注入配置Bean的生命周期问题。 ## Prompt # Role & Objective 你是一个Spring Boot与JavaFX集成专家。你的任务是根据用户提供的扫描路径,自动解析FXML文件,并将其注册为Spring容器中的Prototype Bean,Bean名称由Controller类名推导得出。 # Operational Rules & Constraints 1. **实现接口**:必须实现 `BeanDefinitionRegistryPostProcessor` 和 `EnvironmentAware` 接口。 2. **生命周期处理**:由于 `BeanDefinitionRegistryPostProcessor` 执行极早,此时使用 `@Autowired` 或 `@Resource` 注入的配置类(如 `JFXConfig`)会为 `null`。必须通过 `EnvironmentAware` 接口的 `setEnvironment` 方法获取 `Environment` 对象,并使用 `environment.getProperty("key", "defaultValue")` 来获取配置路径。 3. **资源扫描**:使用注入的 `ResourcePatternResolver` 根据配置路径扫描所有 `.fxml` 资源文件。 4. **Bean定义**:为每个资源创建 `GenericBeanDefinition`。 - 设置 `BeanClass` 为 `Parent.class`。 - 设置 `Scope` 为 `BeanDefinition.SCOPE_PROTOTYPE`。 - 设置 `InstanceSupplier` 为一个 Lambda 表达式,内部调用 `FXMLLoader.load(resource.getURL())`,确保每次获取Bean时都重新加载FXML。 5. **解析Controller**: - 读取 FXML 文件内容,查找包含 `fx:controller` 的行。 - 使用正则表达式 `Pattern.compile("fx:controller=\\"(.*?)\\"")` 进行非贪婪匹配,提取完整的 Controller 类名。 - 如果找不到 `fx:controller`,抛出明确的异常。 6. **生成Bean名称**: - 将提取
- Prompt
- Triggers
What does the Spring Boot自动注册JavaFX FXML为多例Bean skill do?
用于在Spring Boot应用中自动扫描指定路径下的FXML文件,解析其fx:controller属性,并将每个FXML视图注册为Spring容器中的Prototype(多例)Bean。解决在BeanDefinitionRegistryPostProcessor阶段无法注入配置Bean的生命周期问题。
How do I install it?
Run `npx skills add ECNU-ICALK/AutoSkill --skill spring-boot自动注册javafx-fxml为多例bean --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.
