0
votes

All my other Injections are working but it's not working with gson. I have the feeling it's because it's an external package, but I can't resolve the issue. Here are my relevant files:

Producer:

public class GsonFactory {
    @Produces
    public Gson createGson(){return new GsonBuilder().createGson();}
}

injectionpoint:

@ApplicationScoped
public class SoundcloudAPIWrapper implements Serializable{

    @Inject
    private Gson gson;

    public SoundcloudAPIWrapper() {}

    ...

}

Beans.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans
    xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd"
    bean-discovery-mode="all" version="2.0">
</beans>
1
Can you confirm that @Produces is not @javax.ws.rs.Produces, but rather, @javax.enterprise.inject.Producesmaress
So it works if you replace Gson with String?Kukeltje
thank you it was the enterprise @javax.enterprise.inject.Produces . now it's working. But why doesn't @javax.ws.rs.Produces work? All my other factories use the ws.rs . I'm very new to javaee, so an explanation would be great :)Lukas

1 Answers

0
votes

like @maress pointed out in the comment, I needed to replace @javax.ws.rs.Produces with @javax.enterprise.inject.Produces. It's now working