Skip to content

Commit

Permalink
docs: EXPOSED-199 Update configuration section in spring-boot-starter…
Browse files Browse the repository at this point in the history
… README (#1878)

Add sub-section about how to configure other transaction managers alongside Exposed.

Add section about how to log SQL statements in Spring Boot app.
  • Loading branch information
bog-walk authored Oct 16, 2023
1 parent 66ae127 commit 1d45e92
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions exposed-spring-boot-starter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ spring.datasource.username=sa
spring.datasource.password=password
```

## Configuring Exposed
## Configuring Exposed
When using this starter, you can customize the default Exposed configuration by registering a [DatabaseConfig](https://github.com/JetBrains/Exposed/blob/master/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/DatabaseConfig.kt). See the class itself for available configuration options.

Example:
Expand Down Expand Up @@ -109,8 +109,30 @@ fun main(args: Array<String>) {

See the [official documentation](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using.auto-configuration.disabling-specific) for more options to exclude auto-configuration classes.

### Configuring Additional Transaction Managers

Once Exposed has been configured as shown [above](#configuring-exposed), other transaction managers can also be registered by creating their own `@Configuration` class containing a declared transaction manager bean.

To then determine which manager should be used, set the `transactionManager` attribute of `@Transactional` to the qualifier value of the independent transaction manager bean.

Additionally, [custom composed annotations](https://docs.spring.io/spring-framework/reference/data-access/transaction/declarative/annotations.html#tx-custom-attributes) can be defined to reduce repetitive code when switching between these transaction managers:
```kotlin
@Transactional(transactionManager = "springTransactionManager")
annotation class ExposedTransactional

@ExposedTransactional
fun doSomething() {
// ...
}
```

If one of these transaction managers is used predominantly, the `@Primary` annotation can also be used on its bean to give it higher preference.
This ensures that the annotated transaction manager will be the autowired value when `@Transactional` is used without setting the `transactionManager` attribute.

See the [official documentation](https://docs.spring.io/spring-framework/reference/data-access/transaction/declarative/annotations.html#tx-multiple-tx-mgrs-with-attransactional) for more details about handling multiple transaction managers.

## Automatic Schema Creation
This starter will create the database schema if enabled automatically using any class that extends `org.jetbrains.exposed.sql.Table`
Including the property `spring.exposed.generate-ddl` enables this starter to create the database schema automatically using any class that extends `org.jetbrains.exposed.sql.Table`.

Sometimes you will want to exclude packages from the list of auto-created schemas. In this event, the property `spring.exposed.excluded-packages` can be used to exclude everything under the provided packages.

Expand All @@ -120,6 +142,14 @@ spring.exposed.generate-ddl=true
spring.exposed.excluded-packages=com.example.models.ignore,com.example.utils
```

## Logging SQL Statements
Instead of invoking `addLogger()` to log all database transaction statements, add the property `spring.exposed.show-sql` to your configuration file.

### application.properties
```properties
spring.exposed.show-sql=true
```

## Sample

Check out the [Exposed - Spring Boot sample](../samples/exposed-spring/README.md) for more details, for example:
Expand Down

0 comments on commit 1d45e92

Please sign in to comment.