eclipse-ee4j / eclipse-ee4j/jersey

Custom injectors and order of injection

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

Description

I'm attempting to do an @BeanParam, which is not being properly injected. I am not sure if this is a bug, a design limitation, or what.

Anyhow, basically, I use @BeanParam, and I was getting an empty instance, with no injected data. Initially very confusing, until I realized that my custom factory was causing injection of a freshly created instance with no data, and somehow Jersey was putting that in the place of a BeanParam injection.

My experimental factory provide() does the following; note how when it's null, it creates a new copy; that's what was being put in the place of @BeanParam injection...
public ApiKeys.MyModel provide()
{
final HttpSession session = request.getSession();
ApiKeys.MyModel model =
(ApiKeys.MyModel) session.getAttribute("model");
// session.removeAttribute("model");
if (model == null)

{ model = new ApiKeys.MyModel(); }

return model;
}

When I remove the new instance creation, @BeanParam works just fine. The above factory is intended to be used with my custom @SessionAttributeInject(attributeName = "model") but is being activated on apparently any injection.

I'd like to be able to re-use my classes between different injection annotations, as it adds a lot more flexibility.

1\. Is this possible?
2\. Is this a bug or unintended side affect of the design?

Ideally, it might be nice if there was a feature to allow examination of the order of injections, and whether successive injector annotations override previous, or vice versa. In this case, I'm only using @BeanParam, and it's calling my factory either way.
#### Environment
Java 1.8, Linux Mint 17.2
#### Affected Versions
[2.22.2]

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.