SlideShare ist ein Scribd-Unternehmen logo
qaware.de
Wie baue ich eine Spring Boot Library?
Dirk Kröhan
dirk.kroehan@qaware.de
QAware | 2
Dirk Kröhan
Software Architect
@ QAware
#mainz #java
#spring
#cloudnative
Wie findet Spring Boot eigentlich die Beans?
QAware | 3
■ Spring scannt alle packages ausgehend von der @SpringBootApplication Klasse
■ Sucht nach Klassen die annotiert sind mit @Controller, @Service, @Repository, @Component
■ In allen @Configuration Klassen alle mit @Bean annotierten Methoden
Wie findet Spring Boot eigentlich die Beans?
QAware | 4
■ Beans aus Spring Boot Auto Configuration Klassen
– @Configuration Klasse
die in META-INF/spring.factories
unter @EnableAutoConfiguration registriert ist
■ Performance Improvement (siehe Stackoverflow Post)
org.springframework.boot.autoconfigure.EnableAutoConfiguration=
de.qaware.demo.springbootlib.autoconfigure.SpringBootLibAutoConfiguration
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure-processor</artifactId>
<optional>true</optional>
</dependency>
Lässt sich das debuggen?
QAware | 5
■ In der application.yml folgendes Property setzen: debug: true
Spring Configuration
QAware | 6
■ @Configuration Klasse
definiert welche Beans im
Application Context sind
■ Nicht zu verwechseln mit:
@ConfigurationProperties
@Configuration
public class MyConfiguration {
@Bean
public MyService myServiceBean() {
return new MyServiceImpl()
}
}
Conditionals
QAware | 7
■ @ConditionalOnMissingBean erlaubt Library-Nutzern eine Bean
mit eigener Implementierung zu “überschreiben” (Customization)
■ @ConditionalOnClass ermöglicht Prüfung auf Jar-Dependencies.
Oft für Auto Configuration genutzt, in Kombination mit “provided” scope
oder <optional>true</optional>
■ @ConditionalOnProperty um per mylib.enabled: true Funktionalität explizit ein/auszuschalten
Tipp: Einfach mal Spring Boot Code lesen!
■ org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration
■ org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration
Configuration Properties
QAware | 8
■ @ConfigurationProperties Klasse, die mit Konfigurationswerten (Properties) gefüllt wird via
a. Kommandozeilenparametern
b. Umgebungsvariablen
c. (Profile-abhängigen) application.(yaml/properties) Dateien im Classpath
d. Testkonfiguration-Annotationen @TestPropertySource
■ In Libraries mit @EnableConfigurationProperties auf der Auto-Konfiguration Klasse
■ Folgende Dependency nicht vergessen (sonst ist alles gelb in der IDE):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
Projektstruktur: Maven Reactor Multi Module Build
QAware | 9
mylib-parent
- mylib-starter
- mylib-autoconfigure
- mylib-shaded
- mylib-implementation
- …
Demo
Shading
QAware | 11
■ Was ist shading?
– Verstecke eine Dependency durch package renaming + relocation
■ Apache Maven Shade Plugin
– https://maven.apache.org/plugins/maven-shade-plugin/
■ Wie kann shading helfen bei Autoconfiguration in Libs?
– Lib nutzt jmustache (https://github.com/samskivert/jmustache)
– Wir wollen nicht, dass andere Autoconfigurations das sehen
■ Siehe auch:
https://stackoverflow.com/questions/13620281/what-is-the-maven-shade-plugin-used-for-and-
why-would-you-want-to-relocate-java
Shading
QAware | 12
DemoApp DemoApp
springbootlib
jmustache
springbootlib
jmustache de.qaware.demo.springbootlib.shaded.com.samskivert
Maven provided scope vs optional = true
QAware | 13
■ Beide sorgen dafür, dass C und D nicht
transitiv als Dependency für A gelten
– Will man Klassen aus C / D in A nutzen
muss man diese Dependency in A explizit
hinzufügen
■ Provided scope
– D wird von der runtime bereitgestellt
– Bekannt aus thin jars (WAR)
■ Optional = true
– B hat viele Features, eins davon braucht C
– Wenn du in A dieses Features willst,
include C als Dependency
■ Siehe auch:
https://medium.com/@danismaz.furkan/diffe
rence-between-optional-true-optional-and-
scope-provided-scope-7404ec24fb59
Projekt A
(DemoApp)
Projekt B
(springbootlib)
dependency
Projekt C Projekt D
optional provided
Noch lange nicht fertig…
QAware | 14
■ Integrationstests (Spring MVC / WebFlux / Security)
■ Continuous Integration mit SonarQube Analysis
■ Release & Deployment auf Maven Central,
inklusive gleichzeitigem Support für mehrere Spring Boot Versionen
■ Maintenance mit Dependabot
Beispiel: https://github.com/qaware/openapi-generator-for-spring
Feedback welcome (please open issues!)
qaware.de
QAware GmbH Mainz
Rheinstraße 4 C
55116 Mainz
Tel. +49 6131 21569-0
info@qaware.de
twitter.com/qaware
linkedin.com/company/qaware-gmbh
xing.com/companies/qawaregmbh
slideshare.net/qaware
github.com/qaware

Weitere ähnliche Inhalte

Ähnlich wie Wie baue ich eine Spring Boot Library

magnolia mit thymeleaf - ein agiler prozess-beschleuniger
magnolia mit thymeleaf - ein agiler prozess-beschleunigermagnolia mit thymeleaf - ein agiler prozess-beschleuniger
magnolia mit thymeleaf - ein agiler prozess-beschleuniger
Thomas Kratz
 
Agile Oracle database modeling and development - APEX Connect 2020
Agile Oracle database modeling and development - APEX Connect 2020Agile Oracle database modeling and development - APEX Connect 2020
Agile Oracle database modeling and development - APEX Connect 2020
Torsten Kleiber
 
SNoUG 2015 - Vaadin - XPages 2.0?
SNoUG 2015 - Vaadin - XPages 2.0?SNoUG 2015 - Vaadin - XPages 2.0?
SNoUG 2015 - Vaadin - XPages 2.0?
René Winkelmeyer
 
react-de.pdf
react-de.pdfreact-de.pdf
react-de.pdf
ssuser65180a
 
Introduction to Apache Maven 3 (German)
Introduction to Apache Maven 3 (German)Introduction to Apache Maven 3 (German)
Introduction to Apache Maven 3 (German)
Chris Michael Klinger
 
Automatisierung mit grunt
Automatisierung mit gruntAutomatisierung mit grunt
Automatisierung mit grunt
Christian Keuerleber
 
Webcast Nr. 3 - Java Entwicklung mit der SAP Cloud Platform
Webcast Nr. 3 - Java Entwicklung mit der SAP Cloud PlatformWebcast Nr. 3 - Java Entwicklung mit der SAP Cloud Platform
Webcast Nr. 3 - Java Entwicklung mit der SAP Cloud Platform
Patric Dahse
 
DB-Schema-Evolution mit LiquiBase
DB-Schema-Evolution mit LiquiBaseDB-Schema-Evolution mit LiquiBase
DB-Schema-Evolution mit LiquiBase
gedoplan
 
Testing tools
Testing toolsTesting tools
Testing tools
Sebastian Springer
 
Node.js
Node.jsNode.js
TYPO3 Performance (TYPO3camp München)
TYPO3 Performance (TYPO3camp München)TYPO3 Performance (TYPO3camp München)
TYPO3 Performance (TYPO3camp München)
Marcus Schwemer
 
Gradle - Beginner's Workshop (german)
Gradle - Beginner's Workshop (german)Gradle - Beginner's Workshop (german)
Gradle - Beginner's Workshop (german)
Joachim Baumann
 
WP-CLI - Das Kommandozeilen Interface für Wordpress
WP-CLI - Das Kommandozeilen Interface für WordpressWP-CLI - Das Kommandozeilen Interface für Wordpress
WP-CLI - Das Kommandozeilen Interface für Wordpress
frankstaude
 
Fanstatic pycon.de 2012
Fanstatic pycon.de 2012Fanstatic pycon.de 2012
Fanstatic pycon.de 2012Daniel Havlik
 
Einführung in Puppet und Vagrant
Einführung in Puppet und VagrantEinführung in Puppet und Vagrant
Einführung in Puppet und Vagrants0enke
 
JAX 2015 - Continuous Integration mit Java & Javascript
JAX 2015 - Continuous Integration mit Java & JavascriptJAX 2015 - Continuous Integration mit Java & Javascript
JAX 2015 - Continuous Integration mit Java & Javascript
dzuvic
 
Microsoft Azure Platform - System Management v.0.5
Microsoft Azure Platform -  System Management v.0.5 Microsoft Azure Platform -  System Management v.0.5
Microsoft Azure Platform - System Management v.0.5
Oliver Michalski
 
Azure für SysAdmins Eine Reise durch die Cloud v.0.5
Azure für SysAdmins   Eine Reise durch die Cloud v.0.5 Azure für SysAdmins   Eine Reise durch die Cloud v.0.5
Azure für SysAdmins Eine Reise durch die Cloud v.0.5
Oliver Michalski
 
Grails im Überblick und in der Praxis
Grails im Überblick und in der PraxisGrails im Überblick und in der Praxis
Grails im Überblick und in der Praxis
Tobias Kraft
 

Ähnlich wie Wie baue ich eine Spring Boot Library (20)

magnolia mit thymeleaf - ein agiler prozess-beschleuniger
magnolia mit thymeleaf - ein agiler prozess-beschleunigermagnolia mit thymeleaf - ein agiler prozess-beschleuniger
magnolia mit thymeleaf - ein agiler prozess-beschleuniger
 
Agile Oracle database modeling and development - APEX Connect 2020
Agile Oracle database modeling and development - APEX Connect 2020Agile Oracle database modeling and development - APEX Connect 2020
Agile Oracle database modeling and development - APEX Connect 2020
 
SNoUG 2015 - Vaadin - XPages 2.0?
SNoUG 2015 - Vaadin - XPages 2.0?SNoUG 2015 - Vaadin - XPages 2.0?
SNoUG 2015 - Vaadin - XPages 2.0?
 
react-de.pdf
react-de.pdfreact-de.pdf
react-de.pdf
 
Introduction to Apache Maven 3 (German)
Introduction to Apache Maven 3 (German)Introduction to Apache Maven 3 (German)
Introduction to Apache Maven 3 (German)
 
Automatisierung mit grunt
Automatisierung mit gruntAutomatisierung mit grunt
Automatisierung mit grunt
 
Webcast Nr. 3 - Java Entwicklung mit der SAP Cloud Platform
Webcast Nr. 3 - Java Entwicklung mit der SAP Cloud PlatformWebcast Nr. 3 - Java Entwicklung mit der SAP Cloud Platform
Webcast Nr. 3 - Java Entwicklung mit der SAP Cloud Platform
 
DB-Schema-Evolution mit LiquiBase
DB-Schema-Evolution mit LiquiBaseDB-Schema-Evolution mit LiquiBase
DB-Schema-Evolution mit LiquiBase
 
Testing tools
Testing toolsTesting tools
Testing tools
 
Node.js
Node.jsNode.js
Node.js
 
TYPO3 Performance (TYPO3camp München)
TYPO3 Performance (TYPO3camp München)TYPO3 Performance (TYPO3camp München)
TYPO3 Performance (TYPO3camp München)
 
Gradle - Beginner's Workshop (german)
Gradle - Beginner's Workshop (german)Gradle - Beginner's Workshop (german)
Gradle - Beginner's Workshop (german)
 
WP-CLI - Das Kommandozeilen Interface für Wordpress
WP-CLI - Das Kommandozeilen Interface für WordpressWP-CLI - Das Kommandozeilen Interface für Wordpress
WP-CLI - Das Kommandozeilen Interface für Wordpress
 
Fanstatic pycon.de 2012
Fanstatic pycon.de 2012Fanstatic pycon.de 2012
Fanstatic pycon.de 2012
 
Elsholz stoll js_03_10
Elsholz stoll js_03_10Elsholz stoll js_03_10
Elsholz stoll js_03_10
 
Einführung in Puppet und Vagrant
Einführung in Puppet und VagrantEinführung in Puppet und Vagrant
Einführung in Puppet und Vagrant
 
JAX 2015 - Continuous Integration mit Java & Javascript
JAX 2015 - Continuous Integration mit Java & JavascriptJAX 2015 - Continuous Integration mit Java & Javascript
JAX 2015 - Continuous Integration mit Java & Javascript
 
Microsoft Azure Platform - System Management v.0.5
Microsoft Azure Platform -  System Management v.0.5 Microsoft Azure Platform -  System Management v.0.5
Microsoft Azure Platform - System Management v.0.5
 
Azure für SysAdmins Eine Reise durch die Cloud v.0.5
Azure für SysAdmins   Eine Reise durch die Cloud v.0.5 Azure für SysAdmins   Eine Reise durch die Cloud v.0.5
Azure für SysAdmins Eine Reise durch die Cloud v.0.5
 
Grails im Überblick und in der Praxis
Grails im Überblick und in der PraxisGrails im Überblick und in der Praxis
Grails im Überblick und in der Praxis
 

Mehr von QAware GmbH

Mit ChatGPT Dinosaurier besiegen - Möglichkeiten und Grenzen von LLM für die ...
Mit ChatGPT Dinosaurier besiegen - Möglichkeiten und Grenzen von LLM für die ...Mit ChatGPT Dinosaurier besiegen - Möglichkeiten und Grenzen von LLM für die ...
Mit ChatGPT Dinosaurier besiegen - Möglichkeiten und Grenzen von LLM für die ...
QAware GmbH
 
50 Shades of K8s Autoscaling #JavaLand24.pdf
50 Shades of K8s Autoscaling #JavaLand24.pdf50 Shades of K8s Autoscaling #JavaLand24.pdf
50 Shades of K8s Autoscaling #JavaLand24.pdf
QAware GmbH
 
Make Agile Great - PM-Erfahrungen aus zwei virtuellen internationalen SAFe-Pr...
Make Agile Great - PM-Erfahrungen aus zwei virtuellen internationalen SAFe-Pr...Make Agile Great - PM-Erfahrungen aus zwei virtuellen internationalen SAFe-Pr...
Make Agile Great - PM-Erfahrungen aus zwei virtuellen internationalen SAFe-Pr...
QAware GmbH
 
Fully-managed Cloud-native Databases: The path to indefinite scale @ CNN Mainz
Fully-managed Cloud-native Databases: The path to indefinite scale @ CNN MainzFully-managed Cloud-native Databases: The path to indefinite scale @ CNN Mainz
Fully-managed Cloud-native Databases: The path to indefinite scale @ CNN Mainz
QAware GmbH
 
Down the Ivory Tower towards Agile Architecture
Down the Ivory Tower towards Agile ArchitectureDown the Ivory Tower towards Agile Architecture
Down the Ivory Tower towards Agile Architecture
QAware GmbH
 
"Mixed" Scrum-Teams – Die richtige Mischung macht's!
"Mixed" Scrum-Teams – Die richtige Mischung macht's!"Mixed" Scrum-Teams – Die richtige Mischung macht's!
"Mixed" Scrum-Teams – Die richtige Mischung macht's!
QAware GmbH
 
Make Developers Fly: Principles for Platform Engineering
Make Developers Fly: Principles for Platform EngineeringMake Developers Fly: Principles for Platform Engineering
Make Developers Fly: Principles for Platform Engineering
QAware GmbH
 
Der Tod der Testpyramide? – Frontend-Testing mit Playwright
Der Tod der Testpyramide? – Frontend-Testing mit PlaywrightDer Tod der Testpyramide? – Frontend-Testing mit Playwright
Der Tod der Testpyramide? – Frontend-Testing mit Playwright
QAware GmbH
 
Was kommt nach den SPAs
Was kommt nach den SPAsWas kommt nach den SPAs
Was kommt nach den SPAs
QAware GmbH
 
Cloud Migration mit KI: der Turbo
Cloud Migration mit KI: der Turbo Cloud Migration mit KI: der Turbo
Cloud Migration mit KI: der Turbo
QAware GmbH
 
Migration von stark regulierten Anwendungen in die Cloud: Dem Teufel die See...
 Migration von stark regulierten Anwendungen in die Cloud: Dem Teufel die See... Migration von stark regulierten Anwendungen in die Cloud: Dem Teufel die See...
Migration von stark regulierten Anwendungen in die Cloud: Dem Teufel die See...
QAware GmbH
 
Aus blau wird grün! Ansätze und Technologien für nachhaltige Kubernetes-Cluster
Aus blau wird grün! Ansätze und Technologien für nachhaltige Kubernetes-Cluster Aus blau wird grün! Ansätze und Technologien für nachhaltige Kubernetes-Cluster
Aus blau wird grün! Ansätze und Technologien für nachhaltige Kubernetes-Cluster
QAware GmbH
 
Endlich gute API Tests. Boldly Testing APIs Where No One Has Tested Before.
Endlich gute API Tests. Boldly Testing APIs Where No One Has Tested Before.Endlich gute API Tests. Boldly Testing APIs Where No One Has Tested Before.
Endlich gute API Tests. Boldly Testing APIs Where No One Has Tested Before.
QAware GmbH
 
Kubernetes with Cilium in AWS - Experience Report!
Kubernetes with Cilium in AWS - Experience Report!Kubernetes with Cilium in AWS - Experience Report!
Kubernetes with Cilium in AWS - Experience Report!
QAware GmbH
 
50 Shades of K8s Autoscaling
50 Shades of K8s Autoscaling50 Shades of K8s Autoscaling
50 Shades of K8s Autoscaling
QAware GmbH
 
Kontinuierliche Sicherheitstests für APIs mit Testkube und OWASP ZAP
Kontinuierliche Sicherheitstests für APIs mit Testkube und OWASP ZAPKontinuierliche Sicherheitstests für APIs mit Testkube und OWASP ZAP
Kontinuierliche Sicherheitstests für APIs mit Testkube und OWASP ZAP
QAware GmbH
 
Service Mesh Pain & Gain. Experiences from a client project.
Service Mesh Pain & Gain. Experiences from a client project.Service Mesh Pain & Gain. Experiences from a client project.
Service Mesh Pain & Gain. Experiences from a client project.
QAware GmbH
 
50 Shades of K8s Autoscaling
50 Shades of K8s Autoscaling50 Shades of K8s Autoscaling
50 Shades of K8s Autoscaling
QAware GmbH
 
Blue turns green! Approaches and technologies for sustainable K8s clusters.
Blue turns green! Approaches and technologies for sustainable K8s clusters.Blue turns green! Approaches and technologies for sustainable K8s clusters.
Blue turns green! Approaches and technologies for sustainable K8s clusters.
QAware GmbH
 
Per Anhalter zu Cloud Nativen API Gateways
Per Anhalter zu Cloud Nativen API GatewaysPer Anhalter zu Cloud Nativen API Gateways
Per Anhalter zu Cloud Nativen API Gateways
QAware GmbH
 

Mehr von QAware GmbH (20)

Mit ChatGPT Dinosaurier besiegen - Möglichkeiten und Grenzen von LLM für die ...
Mit ChatGPT Dinosaurier besiegen - Möglichkeiten und Grenzen von LLM für die ...Mit ChatGPT Dinosaurier besiegen - Möglichkeiten und Grenzen von LLM für die ...
Mit ChatGPT Dinosaurier besiegen - Möglichkeiten und Grenzen von LLM für die ...
 
50 Shades of K8s Autoscaling #JavaLand24.pdf
50 Shades of K8s Autoscaling #JavaLand24.pdf50 Shades of K8s Autoscaling #JavaLand24.pdf
50 Shades of K8s Autoscaling #JavaLand24.pdf
 
Make Agile Great - PM-Erfahrungen aus zwei virtuellen internationalen SAFe-Pr...
Make Agile Great - PM-Erfahrungen aus zwei virtuellen internationalen SAFe-Pr...Make Agile Great - PM-Erfahrungen aus zwei virtuellen internationalen SAFe-Pr...
Make Agile Great - PM-Erfahrungen aus zwei virtuellen internationalen SAFe-Pr...
 
Fully-managed Cloud-native Databases: The path to indefinite scale @ CNN Mainz
Fully-managed Cloud-native Databases: The path to indefinite scale @ CNN MainzFully-managed Cloud-native Databases: The path to indefinite scale @ CNN Mainz
Fully-managed Cloud-native Databases: The path to indefinite scale @ CNN Mainz
 
Down the Ivory Tower towards Agile Architecture
Down the Ivory Tower towards Agile ArchitectureDown the Ivory Tower towards Agile Architecture
Down the Ivory Tower towards Agile Architecture
 
"Mixed" Scrum-Teams – Die richtige Mischung macht's!
"Mixed" Scrum-Teams – Die richtige Mischung macht's!"Mixed" Scrum-Teams – Die richtige Mischung macht's!
"Mixed" Scrum-Teams – Die richtige Mischung macht's!
 
Make Developers Fly: Principles for Platform Engineering
Make Developers Fly: Principles for Platform EngineeringMake Developers Fly: Principles for Platform Engineering
Make Developers Fly: Principles for Platform Engineering
 
Der Tod der Testpyramide? – Frontend-Testing mit Playwright
Der Tod der Testpyramide? – Frontend-Testing mit PlaywrightDer Tod der Testpyramide? – Frontend-Testing mit Playwright
Der Tod der Testpyramide? – Frontend-Testing mit Playwright
 
Was kommt nach den SPAs
Was kommt nach den SPAsWas kommt nach den SPAs
Was kommt nach den SPAs
 
Cloud Migration mit KI: der Turbo
Cloud Migration mit KI: der Turbo Cloud Migration mit KI: der Turbo
Cloud Migration mit KI: der Turbo
 
Migration von stark regulierten Anwendungen in die Cloud: Dem Teufel die See...
 Migration von stark regulierten Anwendungen in die Cloud: Dem Teufel die See... Migration von stark regulierten Anwendungen in die Cloud: Dem Teufel die See...
Migration von stark regulierten Anwendungen in die Cloud: Dem Teufel die See...
 
Aus blau wird grün! Ansätze und Technologien für nachhaltige Kubernetes-Cluster
Aus blau wird grün! Ansätze und Technologien für nachhaltige Kubernetes-Cluster Aus blau wird grün! Ansätze und Technologien für nachhaltige Kubernetes-Cluster
Aus blau wird grün! Ansätze und Technologien für nachhaltige Kubernetes-Cluster
 
Endlich gute API Tests. Boldly Testing APIs Where No One Has Tested Before.
Endlich gute API Tests. Boldly Testing APIs Where No One Has Tested Before.Endlich gute API Tests. Boldly Testing APIs Where No One Has Tested Before.
Endlich gute API Tests. Boldly Testing APIs Where No One Has Tested Before.
 
Kubernetes with Cilium in AWS - Experience Report!
Kubernetes with Cilium in AWS - Experience Report!Kubernetes with Cilium in AWS - Experience Report!
Kubernetes with Cilium in AWS - Experience Report!
 
50 Shades of K8s Autoscaling
50 Shades of K8s Autoscaling50 Shades of K8s Autoscaling
50 Shades of K8s Autoscaling
 
Kontinuierliche Sicherheitstests für APIs mit Testkube und OWASP ZAP
Kontinuierliche Sicherheitstests für APIs mit Testkube und OWASP ZAPKontinuierliche Sicherheitstests für APIs mit Testkube und OWASP ZAP
Kontinuierliche Sicherheitstests für APIs mit Testkube und OWASP ZAP
 
Service Mesh Pain & Gain. Experiences from a client project.
Service Mesh Pain & Gain. Experiences from a client project.Service Mesh Pain & Gain. Experiences from a client project.
Service Mesh Pain & Gain. Experiences from a client project.
 
50 Shades of K8s Autoscaling
50 Shades of K8s Autoscaling50 Shades of K8s Autoscaling
50 Shades of K8s Autoscaling
 
Blue turns green! Approaches and technologies for sustainable K8s clusters.
Blue turns green! Approaches and technologies for sustainable K8s clusters.Blue turns green! Approaches and technologies for sustainable K8s clusters.
Blue turns green! Approaches and technologies for sustainable K8s clusters.
 
Per Anhalter zu Cloud Nativen API Gateways
Per Anhalter zu Cloud Nativen API GatewaysPer Anhalter zu Cloud Nativen API Gateways
Per Anhalter zu Cloud Nativen API Gateways
 

Wie baue ich eine Spring Boot Library

  • 1. qaware.de Wie baue ich eine Spring Boot Library? Dirk Kröhan dirk.kroehan@qaware.de
  • 2. QAware | 2 Dirk Kröhan Software Architect @ QAware #mainz #java #spring #cloudnative
  • 3. Wie findet Spring Boot eigentlich die Beans? QAware | 3 ■ Spring scannt alle packages ausgehend von der @SpringBootApplication Klasse ■ Sucht nach Klassen die annotiert sind mit @Controller, @Service, @Repository, @Component ■ In allen @Configuration Klassen alle mit @Bean annotierten Methoden
  • 4. Wie findet Spring Boot eigentlich die Beans? QAware | 4 ■ Beans aus Spring Boot Auto Configuration Klassen – @Configuration Klasse die in META-INF/spring.factories unter @EnableAutoConfiguration registriert ist ■ Performance Improvement (siehe Stackoverflow Post) org.springframework.boot.autoconfigure.EnableAutoConfiguration= de.qaware.demo.springbootlib.autoconfigure.SpringBootLibAutoConfiguration <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-autoconfigure-processor</artifactId> <optional>true</optional> </dependency>
  • 5. Lässt sich das debuggen? QAware | 5 ■ In der application.yml folgendes Property setzen: debug: true
  • 6. Spring Configuration QAware | 6 ■ @Configuration Klasse definiert welche Beans im Application Context sind ■ Nicht zu verwechseln mit: @ConfigurationProperties @Configuration public class MyConfiguration { @Bean public MyService myServiceBean() { return new MyServiceImpl() } }
  • 7. Conditionals QAware | 7 ■ @ConditionalOnMissingBean erlaubt Library-Nutzern eine Bean mit eigener Implementierung zu “überschreiben” (Customization) ■ @ConditionalOnClass ermöglicht Prüfung auf Jar-Dependencies. Oft für Auto Configuration genutzt, in Kombination mit “provided” scope oder <optional>true</optional> ■ @ConditionalOnProperty um per mylib.enabled: true Funktionalität explizit ein/auszuschalten Tipp: Einfach mal Spring Boot Code lesen! ■ org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration ■ org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration
  • 8. Configuration Properties QAware | 8 ■ @ConfigurationProperties Klasse, die mit Konfigurationswerten (Properties) gefüllt wird via a. Kommandozeilenparametern b. Umgebungsvariablen c. (Profile-abhängigen) application.(yaml/properties) Dateien im Classpath d. Testkonfiguration-Annotationen @TestPropertySource ■ In Libraries mit @EnableConfigurationProperties auf der Auto-Konfiguration Klasse ■ Folgende Dependency nicht vergessen (sonst ist alles gelb in der IDE): <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency>
  • 9. Projektstruktur: Maven Reactor Multi Module Build QAware | 9 mylib-parent - mylib-starter - mylib-autoconfigure - mylib-shaded - mylib-implementation - …
  • 10. Demo
  • 11. Shading QAware | 11 ■ Was ist shading? – Verstecke eine Dependency durch package renaming + relocation ■ Apache Maven Shade Plugin – https://maven.apache.org/plugins/maven-shade-plugin/ ■ Wie kann shading helfen bei Autoconfiguration in Libs? – Lib nutzt jmustache (https://github.com/samskivert/jmustache) – Wir wollen nicht, dass andere Autoconfigurations das sehen ■ Siehe auch: https://stackoverflow.com/questions/13620281/what-is-the-maven-shade-plugin-used-for-and- why-would-you-want-to-relocate-java
  • 12. Shading QAware | 12 DemoApp DemoApp springbootlib jmustache springbootlib jmustache de.qaware.demo.springbootlib.shaded.com.samskivert
  • 13. Maven provided scope vs optional = true QAware | 13 ■ Beide sorgen dafür, dass C und D nicht transitiv als Dependency für A gelten – Will man Klassen aus C / D in A nutzen muss man diese Dependency in A explizit hinzufügen ■ Provided scope – D wird von der runtime bereitgestellt – Bekannt aus thin jars (WAR) ■ Optional = true – B hat viele Features, eins davon braucht C – Wenn du in A dieses Features willst, include C als Dependency ■ Siehe auch: https://medium.com/@danismaz.furkan/diffe rence-between-optional-true-optional-and- scope-provided-scope-7404ec24fb59 Projekt A (DemoApp) Projekt B (springbootlib) dependency Projekt C Projekt D optional provided
  • 14. Noch lange nicht fertig… QAware | 14 ■ Integrationstests (Spring MVC / WebFlux / Security) ■ Continuous Integration mit SonarQube Analysis ■ Release & Deployment auf Maven Central, inklusive gleichzeitigem Support für mehrere Spring Boot Versionen ■ Maintenance mit Dependabot Beispiel: https://github.com/qaware/openapi-generator-for-spring Feedback welcome (please open issues!)
  • 15. qaware.de QAware GmbH Mainz Rheinstraße 4 C 55116 Mainz Tel. +49 6131 21569-0 info@qaware.de twitter.com/qaware linkedin.com/company/qaware-gmbh xing.com/companies/qawaregmbh slideshare.net/qaware github.com/qaware