Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: EXPOSED-199 Update configuration section in spring-boot-starter README #1878

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading