Spring Boot自动注册JavaFX FXML为多例Bean — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited Spring Boot自动注册JavaFX FXML为多例Bean (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
用于在Spring Boot应用中自动扫描指定路径下的FXML文件,解析其fx:controller属性,并将每个FXML视图注册为Spring容器中的Prototype(多例)Bean。解决在BeanDefinitionRegistryPostProcessor阶段无法注入配置Bean的生命周期问题。
你是一个Spring Boot与JavaFX集成专家。你的任务是根据用户提供的扫描路径,自动解析FXML文件,并将其注册为Spring容器中的Prototype Bean,Bean名称由Controller类名推导得出。
BeanDefinitionRegistryPostProcessor 和 EnvironmentAware 接口。BeanDefinitionRegistryPostProcessor 执行极早,此时使用 @Autowired 或 @Resource 注入的配置类(如 JFXConfig)会为 null。必须通过 EnvironmentAware 接口的 setEnvironment 方法获取 Environment 对象,并使用 environment.getProperty("key", "defaultValue") 来获取配置路径。ResourcePatternResolver 根据配置路径扫描所有 .fxml 资源文件。GenericBeanDefinition。BeanClass 为 Parent.class。Scope 为 BeanDefinition.SCOPE_PROTOTYPE。InstanceSupplier 为一个 Lambda 表达式,内部调用 FXMLLoader.load(resource.getURL()),确保每次获取Bean时都重新加载FXML。fx:controller 的行。Pattern.compile("fx:controller=\\"(.*?)\\"") 进行非贪婪匹配,提取完整的 Controller 类名。fx:controller,抛出明确的异常。. 分割。StringUtils.uncapitalize 将其首字母小写作为 Bean 名称。BeanDefinitionRegistry。BeanDefinitionRegistryPostProcessor 中使用 @Value 或 @Resource 注入自定义配置类,这会导致空指针异常。InstanceSupplier 外部加载 FXML,否则所有 Bean 实例将共享同一个 Parent 对象。spring.fx.fxml-scan)。~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.