[[SpringBoot]]
=== *Spring Boot* auto-configuration

The Holon platform provides https://projects.spring.io/spring-boot[Spring Boot^] *auto-configuration* features for the most of the platform modules, including the _core_ module.

To enable the core Spring Boot auto-configuration capabilities, the following artifact must be included in your project dependencies:

[source, xml, subs="attributes+"]
----
<groupId>com.holon-platform.core</groupId>
<artifactId>holon-spring-boot</artifactId>
<version>{revnumber}</version>
----

See below for the available auto-configuration features.

==== Spring context scope auto-configuration

The <<SpringContextScope,Spring context scope>> is automatically enabled.

This has the same effect as using the `@EnableBeanContext` annotation on Spring configuration classes, with the `lookupByType()` attribute set as true by default.

The `holon.context.bean-lookup-by-type` configuration property name can be used to configure the _resource lookup strategy_, enabling or not the _lookup by type_ mode.

TIP: See the <<SpringContextScope>> documentation section for details.

To disable this auto-configuration feature, the link:{apidir}/com/holonplatform/spring/boot/EnableBeanContextAutoConfiguration.html[EnableBeanContextAutoConfiguration^] class can be excluded from the Spring Boot auto-configuration classes:

[source, java]
----
@EnableAutoConfiguration(exclude={EnableBeanContextAutoConfiguration.class})
----

==== Spring _tenant_ scope auto-configuration

If a link:{apidir}/com/holonplatform/core/tenancy/TenantResolver.html[TenantResolver^] type bean is available in Spring application context and a _single candidate_ can be determined, the <<SpringTenantScope>> is automatically registered and enabled.

This has the same effect as using the `@EnableTenantScope` annotation on Spring configuration classes.

TIP: See the <<SpringTenantScope>> documentation section for details about the _tenant_ scope.

To disable this auto-configuration feature, the link:{apidir}/com/holonplatform/spring/boot/TenantScopeAutoConfiguration.html[TenantScopeAutoConfiguration^] class  can be excluded from the Spring Boot auto-configuration classes:

[source, java]
----
@EnableAutoConfiguration(exclude={TenantScopeAutoConfiguration.class})
----

[[JwtConfigurationAutoConfiguration]]
==== `JwtConfiguration` auto-configuration

When at least one property of the `holon.jwt.*` property set is available in Spring environment, and a link:{apidir}/com/holonplatform/auth/jwt/JwtConfiguration.html[JwtConfiguration^] type bean is not already present in the Spring application context, a `JwtConfiguration` bean is automatically created and setted up according to the `holon.jwt.*` configuration property values.

See the <<JwtConfiguration,JWT configuration>> section for details about the available JWT configuration properties.

For example, to setup a `JwtConfiguration` bean using a symmetric signing algorithm, the following configuration properties can be provided using the YAML format:

[source, yaml]
----
holon:
  jwt:
    issuer: example-issuer
    signature-algorithm: HS512
    sharedkey-base64: "eWGZLlCrUjtBZwxgzcLPnA"
    expire-hours: 1
----

Or when an asymmetric signing algorithm is used:

[source, yaml]
----
holon:
  jwt:
    issuer: example-issuer
    expire-hours: 1
    signature-algorithm: RS256
    privatekey:
      encoding: PEM
      source: > 
        -----BEGIN RSA PRIVATE KEY-----
        MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBALv07pB1uFK4fQ3QlHcRSCofMWovYpYp
        hO2Jh31h2hIivC3TbFzWn07pL14d8ec8LIoIYWZAn4L9ZUpEzCPr3nbHpdoPaEcrpqXlgpjO/Jgf8Ysa
        QPWq7ArjWr/ifiORA3vRg2OVhEGD309BccYh9peh/IOpt9EfmWioYlidO+S/AgMBAAECgYB1zoY8y1w1
        lObk4sg7fPyDUjvRt1OOlQV5MQtYPh3F4jmaa3rvEaKWfjevQQufCKtN9QS/Z1/TZWm4TDi7hxpOu6YZ
        gVL9JYHwOvb8opX9Yle9FyLRv4pPdhUkHs7ahzmhPPAf0kSjwKAYlqBmTUzZY5HTRZy/ffpVftPwcl50
        mQJBAOJAromanqe6PDpxnL4IGcPPyn0dWQ3VyTV+i1XkZ8d60nBoLUriG8Ok+ehj4eiEYeK4Ca7GPciM
        EqkZc54XrjsCQQDUq0TRB3V+1mVjJtMixN4I1nb5lo2MVASDjvl/3LCv7LxCZErWLpCjPivMrii+OOAr
        k1VenXV7uTLD/Si9HKdNAkEAlUbn4ZJKq4+MvWLIb/kYRsGKcBI095PeNZVQiVMxxcObpN6XQ5j7iJII
        8PM10hvGGbgja1UQ3ojMpxVL2zr0kQJBANQt1Ejgsj9L1HfqQnjMBeK3Zph5ttus75v6R79kBfxfqyxq
        N6gdaT0VSEm78PZodG/FXUU6v/4ith2INN8I+XkCQQCq77unFpv3OESzhNRa0hjJgAAiwvAqwrWRxLHT
        DijzpQ4PNDfR32bTV/pB9i0nJAPce+9cB7ahx+vpLX2jFuLu
        -----END RSA PRIVATE KEY-----
    publickey:
      encoding: PEM
      source: > 
        -----BEGIN RSA PUBLIC KEY-----
        MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC79O6QdbhSuH0N0JR3EUgqHzFqL2KWKYTtiYd9YdoS
        Irwt02xc1p9O6S9eHfHnPCyKCGFmQJ+C/WVKRMwj6952x6XaD2hHK6al5YKYzvyYH/GLGkD1quwK41q/
        4n4jkQN70YNjlYRBg99PQXHGIfaXofyDqbfRH5loqGJYnTvkvwIDAQAB
        -----END RSA PUBLIC KEY-----   
----

To disable this auto-configuration feature, the link:{apidir}/com/holonplatform/spring/boot/JwtAutoConfiguration.html[JwtAutoConfiguration^] class can be excluded from the Spring Boot auto-configuration classes:

[source, java]
----
@EnableAutoConfiguration(exclude={JwtAutoConfiguration.class})
----

[[Starters]]
==== Spring Boot starters

The following Spring Boot _starter_ artifact is available to provide a quick project configuration setup using Maven dependency system:

_Maven coordinates_:
[source, xml, subs="attributes+"]
----
<groupId>com.holon-platform.core</groupId>
<artifactId>holon-starter</artifactId>
<version>{revnumber}</version>
----

The starter provides the dependency to the `holon-spring-boot` artifact, enabling the auto-configuration features listed above, in addition to the default *core* Spring Boot starter (`spring-boot-starter`), which provides auto-configuration support, logging and YAML support.

See the link:https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using-boot-starter[Spring Boot starters documentation^] for details about the Spring Boot _starters_ topic and the core Spring Boot starter features.
