i'm using android studio with spring framework, but import…
- User
i'm using android studio with spring framework, but import jakarta.transaction.Transactional; Cannot resolve symbol 'jakarta'
- Assistant
jakarta.transaction.Transactionalonly exists if Jakarta EE 9+ libraries are on your class-path.
If the IDE (Android Studio / IntelliJ) “Cannot resolve symboljakarta”, one of two things is happening:──────────────────────────────────────────────────────────────────────────────
- You are on Spring Boot 2.x / Spring 5 (still using the old
javaxnamespace) ➜ use the correct import or upgrade. - You are already on Spring Boot 3.x / Spring 6 but the
jakarta.transaction-apiJAR is missing ➜ add the dependency. ──────────────────────────────────────────────────────────────────────────────
Below you’ll find the quick fixes for both scenarios.
A) You are on Spring Boot ≤ 2.7 (“javax world”)
Spring Boot 2 still ships Jakarta EE 8 which keeps the old package names.
• Replace the import with Spring’s own annotation (recommended):
import org.springframework.transaction.annotation.Transactional;or, if you really want the JTA one, use the legacy package:
import javax.transaction.Transactional;That’s it—no extra dependency is required because
spring-txis already brought in by everyspring-boot-starter-*.
B) You are on Spring Boot 3.x / Spring 6 (“jakarta world”) but the API JAR is missing
Boot 3 uses Jakarta EE 10 → all
javax.*packages were renamed tojakarta.*. Normally the starter POMs/gradle plugins pull the transaction API in automatically.
If you created a custom, ultra-minimal build you may need to add it explicitly:Gradle (Groovy DSL)
dependencies { implementation 'org.springframework.boot:spring-boot-starter' implementation 'jakarta.transaction:jakarta.transaction-api:2.0.1' // <-- add }Gradle (Kotlin DSL)
dependencies { implementation("org.springframework.boot:spring-boot-starter") implementation("jakarta.transaction:jakarta.transaction-api:2.0.1") }Maven
<dependency> <groupId>jakarta.transaction</groupId> <artifactId>jakarta.transaction-api</artifactId> <version>2.0.1</version> </dependency>After you refresh/ re-import the project, the IDE should resolve
jakarta.transaction.Transactionalwithout complaints.
Which approach should I pick?
• Staying on Spring Boot 2.x? Use
org.springframework.transaction.annotation.Transactional(orjavax.transaction.Transactional) and postponejakarta.*until you upgrade.• Already upgraded to Spring Boot 3.x? Keep the
jakarta.transaction.Transactionalimport and make sure thejakarta.transaction-apiJAR is present (usually via the standard Spring Boot starters).If you’re not sure which version you’re on, open
build.gradle/pom.xmland look for:org.springframework.boot VERSION–
2.x.y→ javax world
–3.x.y→ jakarta worldHappy coding 👋
- You are on Spring Boot 2.x / Spring 5 (still using the old
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.