[[spring-testing-annotation-beforetransaction]]
= `@BeforeTransaction`

`@BeforeTransaction` indicates that the annotated `void` method should be run before a
transaction is started, for test methods that have been configured to run within a
transaction by using Spring's `@Transactional` annotation. `@BeforeTransaction` methods
are not required to be `public` and may be declared on interface default methods.

The following example shows how to use the `@BeforeTransaction` annotation:

[tabs]
======
Java::
+
[source,java,indent=0,subs="verbatim,quotes"]
----
	@BeforeTransaction // <1>
	void beforeTransaction() {
		// logic to be run before a transaction is started
	}
----
<1> Run this method before a transaction.

Kotlin::
+
[source,kotlin,indent=0,subs="verbatim,quotes"]
----
	@BeforeTransaction // <1>
	fun beforeTransaction() {
		// logic to be run before a transaction is started
	}
----
<1> Run this method before a transaction.
======
