SpringOne2GX 2013 是由 Pivotal当时为 VMware SpringSource主办的年度 Spring 技术大会聚焦 Spring 生态系统的最新进展与最佳实践。其中题为“Building Your Java Configuration Muscle Memory”的演讲通常由 Spring 团队核心成员如 Chris Beams 或 Josh Long 主讲旨在倡导从传统的 XML 配置转向基于 Java 的类型安全配置Configuration Bean并强调通过持续实践形成“肌肉记忆”——即让开发者本能地优先使用 Java Config 而非 XML。该主题核心要点包括✅Java Config 的优势编译期检查、IDE 支持自动补全/重构安全、可调试性、条件化配置Conditional、模块化与组合性XML 的局限运行时错误、难以重构、缺乏类型安全、配置分散 关键注解Configuration,Bean,Import,Profile,ConditionalOnClass虽后者在 Spring Boot 中更成熟但思想源于此时的演进 “Muscle Memory” 强调通过刻意练习如禁用 XML、团队编码规范、模板代码生成使 Java 配置成为默认反射式选择。该演讲是 Spring 向现代声明式、编程式配置范式转型的重要里程碑也为后续 Spring Boot 的自动配置auto-configuration理念埋下伏笔。ConfigurationpublicclassDataSourceConfig{BeanProfile(dev)publicDataSourceh2DataSource(){returnnewHikariDataSource(newHikariConfig(Map.of(jdbcUrl,jdbc:h2:mem:testdb,driverClassName,org.h2.Driver)));}BeanProfile(prod)publicDataSourcepostgresDataSource(Value(${db.url})Stringurl){varconfignewHikariConfig();config.setJdbcUrl(url);returnnewHikariDataSource(config);}}SpringOne2GX 2013 Replay: Building Your Java Configuration Muscle MemoryRecorded at SpringOne2GX 2013 in Santa Clara, CASpeakers: Phil Webb and Josh LongUsing a module that provides a Spring XML namespace and integration API is muscle memory for most people: add the .xsd to the imported XML schemas for the configuration file, maybe enable a annotation-driven variant if it’s available, autocomplete some XML stanzas, and then you’re set! But what about Java configuration? Java configuration has been around in some form since at least 2005. It was merged into the core framework in 2009 and since then we’ve seen a slew of new Java configuration-powered DSLs pop up. 2013, in particular, has seen alpha-or-better cuts of Java configuration support for Spring MVC, Spring Security (and Spring Security OAuth), Spring Batch, Spring Social, Spring Data (including all the modules under it: REST, MongoDB, JPA, Neo4j, Redis, etc), Spring HATEOAS, and more all provide milestone-or-better cuts of a Java configuration integration. Tomcat 7 (and all Servlet 3-compatible containers) offer a programmatic alternative to web.xml. This provides another great integration hook for modules that wish to integrate with the web container, removing the configuration burden from the user. There’s a lot of power here and it’s easy to get started if you know what to look for. In this talk, join Spring Developer Advocate Josh Long and Spring-core commmitter, all-around nice guy, and Spring Boot ninja Phil Webb as they introduce the Java configuration support in the various Spring projects, show how to approach them when integrating them into your code, and - if the situation demands - how to write your own Java configuration DSL. Learn more about JavaConfig at http://projects.spring.io/spring-frameworkLearn more about Java Configuration and Spring at http://projects.spring.io/spring-frameworkLearn more about Spring Guides at http://www.spring.io/guides