Jakarta Annotation API

The Jakarta Annotation API provides standard annotations for Java applications, widely used to add metadata to Java code, improving code structure and consistency.

Maven Dependency

<dependency>
  <groupId>jakarta.annotation</groupId>
  <artifactId>jakarta.annotation-api</artifactId>
  <version>2.1.1</version>
</dependency>

Compatibility of Jakarta Annotation API with Java & Spring Versions

VersionMinimum Java VersionSpring Framework VersionSpring Boot Version
2.0.0 Java 84.3.x1.5.x
2.1.0 Java 85.0.x2.0.x
2.1.1 Java 85.0.x2.1.x
3.0.0 LatestJava 115.3.x2.5.x

Common Java Classes

Known Vulnerabilities

Vulnerabilities:

IDDescriptionFixed in Version
Potential XML External Entity Injection2.1.1

Common Errors and Troubleshooting

1. Missing @Inject or @Qualifier for Ambiguous Dependencies

If there are multiple beans of the same type and the application tries to inject one of them without disambiguating using @Qualifier, an exception is thrown.

Code Snippet

@Component
public class UserServiceImpl1 implements UserService {
    // Implementation 1
}

@Component
public class UserServiceImpl2 implements UserService {
    // Implementation 2
}

@RestController
public class UserController {

    @Inject // Jakarta Annotations
    private UserService userService; // Ambiguous dependency without @Qualifier

    @GetMapping("/user")
    public String getUser() {
        return "User Service";
    }
}

Stack Trace

ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'testService': No qualifying bean of type 'com.mavenmq.app.service.impl.UserService' available: expected single matching bean but found 2: userServiceImpl1,userServiceImpl2 2024-12-14T14:22:39.988+05:30 INFO 30492 --- [MavenMQ] [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default' Hibernate: drop table if exists employees cascade Hibernate: drop table if exists post cascade Hibernate: drop table if exists users cascade 2024-12-14T14:22:40.008+05:30 INFO 30492 --- [MavenMQ] [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated... 2024-12-14T14:22:40.012+05:30 INFO 30492 --- [MavenMQ] [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed. 2024-12-14T14:22:40.015+05:30 INFO 30492 --- [MavenMQ] [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2024-12-14T14:22:40.054+05:30 INFO 30492 --- [MavenMQ] [ main] .s.b.a.l.ConditionEvaluationReportLogger : Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled. 2024-12-14T14:22:40.100+05:30 ERROR 30492 --- [MavenMQ] [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Field testService in com.mavenmq.app.UserController required a single bean, but 2 were found: - userServiceImpl1: defined in file [/home/workspace/java/MavenMQ/target/classes/com/mavenmq/app/service/impl/UserServiceImpl1.class] - userServiceImpl2: defined in file [/home/workspace/java/MavenMQ/target/classes/com/mavenmq/app/service/impl/UserServiceImpl2.class] This may be due to missing parameter name information Action: Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed Ensure that your compiler is configured to use the '-parameters' flag. You may need to update both your build tool settings as well as your IDE. (See https://github.com/spring-projects/spring-framework/wiki/Upgrading-to-Spring-Framework-6.x#parameter-name-retention) Process finished with exit code 1

2. Circular Dependency with @Inject

A circular dependency occurs when two or more beans depend on each other directly or indirectly.

Code Snippet

@Component
public class UserServiceImpl1 implements UserService {

    @Inject
    private UserServiceImpl2 userServiceImpl2;
}

@Component
public class UserServiceImpl2 implements UserService{

    @Inject
    private UserServiceImpl1 userServiceImpl1;
}

Stack Trace

ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'testService': Error creating bean with name 'userServiceImpl1': Unsatisfied dependency expressed through field 'userRepository': Error creating bean with name 'userServiceImpl2': Unsatisfied dependency expressed through field 'userService': Error creating bean with name 'userServiceImpl1': Requested bean is currently in creation: Is there an unresolvable circular reference or an asynchronous initialization dependency? 2024-12-14T15:27:52.535+05:30 INFO 45175 --- [MavenMQ] [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default' Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled. 2024-12-14T15:27:52.838+05:30 ERROR 45175 --- [MavenMQ] [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: The dependencies of some of the beans in the application context form a cycle: userController (field private com.mavenmq.app.service.impl.UserServiceImpl1 com.mavenmq.app.UserController.testService) ┌─────┐ | userServiceImpl1 (field private com.mavenmq.app.service.impl.UserServiceImpl2 com.mavenmq.app.service.impl.UserServiceImpl1.userRepository) ↑ ↓ | userServiceImpl2 (field private com.mavenmq.app.service.impl.UserServiceImpl1 com.mavenmq.app.service.impl.UserServiceImpl2.userService) └─────┘ Action: Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true. Process finished with exit code 1

Manifest File Information

Manifest Info


Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Jakarta Annotation API
Bundle-SymbolicName: jakarta.annotation-api
Bundle-Version: 2.1.1
Bundle-Description: Jakarta Annotation API provides the specifications for common Java annotations.
Bundle-License: https://www.eclipse.org/legal/epl-2.0/
Export-Package: jakarta.annotation;version="2.1.1"
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version>=8))"
Bundle-Vendor: Eclipse Foundation
Automatic-Module-Name: jakarta.annotation
Specification-Title: Jakarta Annotation API
Specification-Version: 2.1
Specification-Vendor: Eclipse Foundation
Implementation-Title: jakarta.annotation-api
Implementation-Version: 2.1.1
Implementation-Vendor: Eclipse Foundation

References

View Documentation

References

© 2024 MavenMQ.com. All Rights Reserved.     PrivacyPolicy      SiteMap      Facebook