Kiril Kirilov
Kiril Kirilov

Reputation: 11257

How to @Inject a third party class in JavaEE

In the following example, how to inject a class from third-party library? For example

@Stateless
class MyStatelessService
{
@Inject Gson gson;
...
}

I suppose that I must create some bean injector class responsible for all third party classes. How to do that?

Upvotes: 2

Views: 827

Answers (1)

Kris
Kris

Reputation: 5792

You would have to create a specialized producer for the type you want to inject. Perfect example already exists for you - it is a Logger injection using the weld extensions.

@Inject
Logger log;

You can have a look into the weld extension here:

https://github.com/weld/extensions/blob/master/impl/src/main/java/org/jboss/weld/extensions/log/

and the Producer.java itself here:

https://github.com/weld/extensions/blob/master/impl/src/main/java/org/jboss/weld/extensions/log/Producers.java

Upvotes: 3

Related Questions