Accelerating Development
with Organizational Opinions
October 7–10, 2019
Austin Convention Center
Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
MUST CODE
FASTER!
Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
LESS CODE
Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
What are Organizational Opinions?
Spring Boot is “Opinionated”
• Investigates its environment (configuration, libraries, etc.)
• Instantiates beans and executes logic to establish default behavior
• Delivered through Spring Boot autoconfiguration
Organizational Opinions
• Implementation of standards through autoconfiguration
• Security, Operations, etc.
4
Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Goal: Keep developers focused on…
Business Functionality
Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
We get to enjoy…
• Predictability
• Typical behavior by default
• Consistency
• Easy for them to do the right thing
• Manage the 20%
• Supportability
• Operations out-of-the-box
• Sleep
Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Developer Experience
What should be the Developer Experience?
• Should they have any choice?
How do they communicate intended behavior?
• Declared through an annotation?
• Bean construction?
How can they customize behavior?
• Configuration properties?
• Bean construction?
What about Operations?
• Should it include a HealthCheck bean?
7
Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Opinion Ownership
Opinions come in many forms…
Enterprise-wide
• Logging, Tracing
Technology-specific
• Configuration, Platform Security
Departmental
• Application-nuanced, layered on Enterprise/Technology
8
Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Lets Pair On an Example!
Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Developer Experience – Acceptance Criteria
• RestTemplate Beans should be configured to log all outbound requests when
Bean is annotated with “@RequestLogging”
• Request logging should be enabled by default and should be disabled by
setting the property “request.logging.enabled=false”
1
0
Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Developer Experience
@Configuration
public class ExampleApplicationConfiguration {
@Bean
@RequestLogging
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
@Qualifier
public @interface RequestLogging {}
Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Option 1 - BeanPostProcessor
@Configuration
public class RequestLoggingConfiguration {
public BeanPostProcessor postProcessor() {
return new BeanPostProcessor() {
@Override
public Object postProcessAfterInitialization(Object bean, String beanName)
throws BeansException {
if (bean instanceof RestTemplate) {
...
}
return bean;
}
};
}
}
Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Option 2 - SmartInitializingSingleton
@Configuration
public class RequestLoggingConfiguration {
@Autowired(required = false)
@RequestLogging
private List<RestTemplate> restTemplates;
@Bean
public SmartInitializingSingleton requestLoggingRestTemplateInitializer() {
return () -> this.restTemplate.forEach(restTemplate -> {…});
}
}
Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
WE ARE DONE!
Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Oh No!
Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Developer Experience – Acceptance Criteria
• Request logging should be enabled by default and should be disabled by
setting the property `request.logging.enabled=false`
1
6
Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Option 1 - @Enable* Annotation
@Configuration
@EnableRequestLogging
public class ExampleApplicationConfiguration {
}
1
7
@Import(RequestLoggingConfiguration.class)
public @interface EnableRequestLogging {
}
Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Option 2 – spring.factories
META-INF/spring.factories
org.springframework.boot.autoconfigure.EnableAutoConfiguration=
com.acme.RequestLoggingAutoConfiguration
@Configuration
public class RequestLoggingAutoConfiguration {
…
}
1
8
Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Option 2+ – conditional spring.factories
1
9
META-INF/spring.factories
org.springframework.boot.autoconfigure.EnableAutoConfiguration=
com.acme.RequestLoggingAutoConfiguration
@Configuration
@ConditionalOnProperty(name=“request.logging.enabled”, havingValue=“true”)
public class RequestLoggingAutoConfiguration {
…
}
Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Testing
@Test
public void betterTestMethodNameHere() {
new ApplicationContextRunner()
.withUserConfiguration(RequestLoggingAutoConfiguration.class)
.withPropertyValues(”request.logging.enabled=false")
.run(context -> {
assertThat(context).doesNotHaveBean("initializingSingleton");
});
}
Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
WE ARE FINALLY DONE!
Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Recap
@Configuration
@ConditionalOnProperty(name=“request.logging.enabled”, havingValue=“true”)
public class RequestLoggingAutoConfiguration {
@Autowired(required = false)
@RequestLogging
private List<RestTemplate> restTemplates;
@Bean
public SmartInitializingSingleton requestLoggingRestTemplateInitializer() {
return () -> this.restTemplate.forEach(restTemplate -> {…});
}
}
META-INF/spring.factories
org.springframework.boot.autoconfigure.EnableAutoConfiguration=
com.acme.RequestLoggingAutoConfiguration
Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Recommendations
- Configuration Processor Library
- org.springframework.boot:spring-boot-configuration-processor
- Configuration Property IDE Hints
- Autoconfiguration Processor Library
- org.springframework.boot:spring-boot-autoconfigure-processor
- Indexes Auto-Configurations for Faster Application Start Times
Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Additional Configuration Points
- EnvironmentPostProcessor
- Load Additional Property Sources
- ApplicationListeners
- Make changes based on application events
- ConfigurationPropertyBindingPostProcessor
- Makes changes to any @ConfigurationProperty Beans
- SecurityConfigurer
- Allows for Customizing Spring Security Configuration
Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Additional Autoconfiguration Conditionals
- @Conditional
- @ConditionalOnBean
- @ConditionalOnMissingBean
- @ConditionalOnResource
- @ConditionalOnClass
- @ConditionalOnMissingClass
- @ConditionalOnCloudPlatform
- @ConditionalOnWebApplication
- @ConditionalOnExpression
Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
https://linkedin.com/in/tristanchansonhttps://www.linkedin.com/in/chris-kirk-b321853

Accelerating Development with Organizational Opinions

  • 1.
    Accelerating Development with OrganizationalOpinions October 7–10, 2019 Austin Convention Center
  • 2.
    Unless otherwise indicated,these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ MUST CODE FASTER!
  • 3.
    Unless otherwise indicated,these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ LESS CODE
  • 4.
    Unless otherwise indicated,these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What are Organizational Opinions? Spring Boot is “Opinionated” • Investigates its environment (configuration, libraries, etc.) • Instantiates beans and executes logic to establish default behavior • Delivered through Spring Boot autoconfiguration Organizational Opinions • Implementation of standards through autoconfiguration • Security, Operations, etc. 4
  • 5.
    Unless otherwise indicated,these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Goal: Keep developers focused on… Business Functionality
  • 6.
    Unless otherwise indicated,these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ We get to enjoy… • Predictability • Typical behavior by default • Consistency • Easy for them to do the right thing • Manage the 20% • Supportability • Operations out-of-the-box • Sleep
  • 7.
    Unless otherwise indicated,these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Developer Experience What should be the Developer Experience? • Should they have any choice? How do they communicate intended behavior? • Declared through an annotation? • Bean construction? How can they customize behavior? • Configuration properties? • Bean construction? What about Operations? • Should it include a HealthCheck bean? 7
  • 8.
    Unless otherwise indicated,these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Opinion Ownership Opinions come in many forms… Enterprise-wide • Logging, Tracing Technology-specific • Configuration, Platform Security Departmental • Application-nuanced, layered on Enterprise/Technology 8
  • 9.
    Unless otherwise indicated,these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Lets Pair On an Example!
  • 10.
    Unless otherwise indicated,these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Developer Experience – Acceptance Criteria • RestTemplate Beans should be configured to log all outbound requests when Bean is annotated with “@RequestLogging” • Request logging should be enabled by default and should be disabled by setting the property “request.logging.enabled=false” 1 0
  • 11.
    Unless otherwise indicated,these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Developer Experience @Configuration public class ExampleApplicationConfiguration { @Bean @RequestLogging public RestTemplate restTemplate() { return new RestTemplate(); } } @Qualifier public @interface RequestLogging {}
  • 12.
    Unless otherwise indicated,these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Option 1 - BeanPostProcessor @Configuration public class RequestLoggingConfiguration { public BeanPostProcessor postProcessor() { return new BeanPostProcessor() { @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof RestTemplate) { ... } return bean; } }; } }
  • 13.
    Unless otherwise indicated,these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Option 2 - SmartInitializingSingleton @Configuration public class RequestLoggingConfiguration { @Autowired(required = false) @RequestLogging private List<RestTemplate> restTemplates; @Bean public SmartInitializingSingleton requestLoggingRestTemplateInitializer() { return () -> this.restTemplate.forEach(restTemplate -> {…}); } }
  • 14.
    Unless otherwise indicated,these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ WE ARE DONE!
  • 15.
    Unless otherwise indicated,these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Oh No!
  • 16.
    Unless otherwise indicated,these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Developer Experience – Acceptance Criteria • Request logging should be enabled by default and should be disabled by setting the property `request.logging.enabled=false` 1 6
  • 17.
    Unless otherwise indicated,these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Option 1 - @Enable* Annotation @Configuration @EnableRequestLogging public class ExampleApplicationConfiguration { } 1 7 @Import(RequestLoggingConfiguration.class) public @interface EnableRequestLogging { }
  • 18.
    Unless otherwise indicated,these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Option 2 – spring.factories META-INF/spring.factories org.springframework.boot.autoconfigure.EnableAutoConfiguration= com.acme.RequestLoggingAutoConfiguration @Configuration public class RequestLoggingAutoConfiguration { … } 1 8
  • 19.
    Unless otherwise indicated,these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Option 2+ – conditional spring.factories 1 9 META-INF/spring.factories org.springframework.boot.autoconfigure.EnableAutoConfiguration= com.acme.RequestLoggingAutoConfiguration @Configuration @ConditionalOnProperty(name=“request.logging.enabled”, havingValue=“true”) public class RequestLoggingAutoConfiguration { … }
  • 20.
    Unless otherwise indicated,these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Testing @Test public void betterTestMethodNameHere() { new ApplicationContextRunner() .withUserConfiguration(RequestLoggingAutoConfiguration.class) .withPropertyValues(”request.logging.enabled=false") .run(context -> { assertThat(context).doesNotHaveBean("initializingSingleton"); }); }
  • 21.
    Unless otherwise indicated,these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ WE ARE FINALLY DONE!
  • 22.
    Unless otherwise indicated,these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Recap @Configuration @ConditionalOnProperty(name=“request.logging.enabled”, havingValue=“true”) public class RequestLoggingAutoConfiguration { @Autowired(required = false) @RequestLogging private List<RestTemplate> restTemplates; @Bean public SmartInitializingSingleton requestLoggingRestTemplateInitializer() { return () -> this.restTemplate.forEach(restTemplate -> {…}); } } META-INF/spring.factories org.springframework.boot.autoconfigure.EnableAutoConfiguration= com.acme.RequestLoggingAutoConfiguration
  • 23.
    Unless otherwise indicated,these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Recommendations - Configuration Processor Library - org.springframework.boot:spring-boot-configuration-processor - Configuration Property IDE Hints - Autoconfiguration Processor Library - org.springframework.boot:spring-boot-autoconfigure-processor - Indexes Auto-Configurations for Faster Application Start Times
  • 24.
    Unless otherwise indicated,these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Additional Configuration Points - EnvironmentPostProcessor - Load Additional Property Sources - ApplicationListeners - Make changes based on application events - ConfigurationPropertyBindingPostProcessor - Makes changes to any @ConfigurationProperty Beans - SecurityConfigurer - Allows for Customizing Spring Security Configuration
  • 25.
    Unless otherwise indicated,these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Additional Autoconfiguration Conditionals - @Conditional - @ConditionalOnBean - @ConditionalOnMissingBean - @ConditionalOnResource - @ConditionalOnClass - @ConditionalOnMissingClass - @ConditionalOnCloudPlatform - @ConditionalOnWebApplication - @ConditionalOnExpression
  • 26.
    Unless otherwise indicated,these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ https://linkedin.com/in/tristanchansonhttps://www.linkedin.com/in/chris-kirk-b321853