eclipse-ee4j / eclipse-ee4j/jersey

@Context doesn't work on CDI beans in Tomcat

Open
#3,260 8 comments 0 reactions 0 assignees View on GitHub
Component: containers Priority: Major Type: Bug
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

With Jersey 2.20 I can use @Context on a CDI bean like this:

```
@ApplicationScoped
public class SomeBean {

@Context
private Configuration configuration;

}
```

With Jersey 2.21 and 2.22.1 the injection doesn't work any more and I get null for the configuration.

This came up because the MVC RI Ozark relies on this behavior. See [OZARK-61](https://java.net/jira/browse/OZARK-61 "NPE after updating from Jersey 2.19 to 2.21") for the original issue.

I'll attach a minimal Maven project for demonstration. Steps to reproduce:

1. Build the project and deploy it to Tomcat 8
2. Open [http://localhost:8080/r/test](http://localhost:8080/r/test)
3. You will see that injection worked fine
4. Now open pom.xml and change the Jersey version to 2.22.1
5. Build and deploy it again
6. Open [http://localhost:8080/r/test](http://localhost:8080/r/test)
7. You will see that injection did not work
#### Environment
Apache Tomcat 8.0.23, Weld 3.0.0.Alpha13 and latest stable version
#### Affected Versions
[2.21, 2.22, 2.22.1]

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.