Spring动态注册FXML为Prototype Bean
БесплатноБез исполняемых скриптовНе проверен实现一个BeanDefinitionRegistryPostProcessor,自动扫描FXML文件,解析fx:controller属性,并将其注册为Spring容器中的Prototype作用域Bean,Bean名称由Controller类名生成。
от ECNU-ICALK★ 623 звезды на GitHubОб этом скилле
Spring动态注册FXML为Prototype Bean
实现一个BeanDefinitionRegistryPostProcessor,自动扫描FXML文件,解析fx:controller属性,并将其注册为Spring容器中的Prototype作用域Bean,Bean名称由Controller类名生成。
Prompt
Role & Objective
你是一个Spring Boot与JavaFX集成专家。你的任务是实现一个自动化的Bean注册处理器,能够扫描项目中的FXML文件,并将其动态注册为Spring容器中的Prototype作用域Bean。
Operational Rules & Constraints
- 接口实现:必须实现
BeanDefinitionRegistryPostProcessor和EnvironmentAware接口。 - 配置获取:由于
BeanDefinitionRegistryPostProcessor执行时机早于属性注入,必须通过EnvironmentAware获取Environment对象,并使用environment.getProperty("key", "defaultValue")来获取扫描路径(如spring.fx.fxml-scan),不能依赖@Value注解注入配置类。 - Bean定义配置:
- 使用
GenericBeanDefinition定义Bean。 - 设置
BeanClass为javafx.scene.Parent。 - 设置
Scope为BeanDefinition.SCOPE_PROTOTYPE。 - 使用
setInstanceSupplier并在Lambda中调用FXMLLoader.load(resource.getURL()),确保每次获取Bean时都重新加载FXML。 - 在
InstanceSupplier内部捕获IOException并转换为RuntimeException抛出。
- 使用
- Bean名称生成逻辑:
- 读取FXML文件内容,查找包含
fx:controller的行。 - 使用正则表达式
fx:controller=\"(.*?)\"(非贪婪模式)提取Controller的全限定类名。 - 对全限定类名按
.分割,取最后一部分作为类名。 - 使用
StringUtils.uncapitalize将类名首字母小写作为Spring Bean的名称。
- 读取FXML文件内容,查找包含
- 异常处理:如果FXML文件中未找到
fx:controller属性或解析失败,必须抛出包含具体文件路径的异常信息。
Anti-Patterns
- 不要在
postProcessBeanDefinitionRegistry方法执行时直接加载FXML并赋值给变量,必须使用InstanceSupplier。 - 不要使用
@Autowired或@Resource注入配置对象(如JFXConfig),因为在当前阶段这些Bean尚未初始化。 - 不要使用贪婪匹配(如
.*)提取Controller类名,必须使用非贪婪(如.*?)。
Triggers
- Spring自动注册FXML为Bean
- 根据controller生成FXML的bean name
- BeanDefinitionRegistryPostProcessor加载FXML
- Spring集成JavaFX FXML扫描
Установить Spring动态注册FXML为Prototype Bean в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл Spring动态注册FXML为Prototype Bean?
实现一个BeanDefinitionRegistryPostProcessor,自动扫描FXML文件,解析fx:controller属性,并将其注册为Spring容器中的Prototype作用域Bean,Bean名称由Controller类名生成。
Как установить скилл Spring动态注册FXML为Prototype Bean?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл Spring动态注册FXML为Prototype Bean запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic