i'm using Open Liberty 23.0.0.12 on OpenJDK 21.0.1+12-29 for my application. After upgrading the server.xml to use Jakarta EE Web Profile 10.0 instead of 9.1, injections in ClientHeadersFactory
doesn't work anymore. In the following sample code, myBean is always null
.
public class MyFactory implements ClientHeadersFactory {
@Inject
private MyBean myBean;
@Override
public MultivaluedMap<String, String> update(MultivaluedMap<String, String> incomingHeaders, MultivaluedMap<String, String> clientOutgoingHeaders) {
}
}
The class MyBean
@RequestScoped
public class MyBean {
}
The relevant maven dependency is jakarta.platform:jakarta.jakartaee-api:10.0.0.
I already nailed it down to something related to the upgrade to Jakarta EE 10 itself.
I upgraded the beans.xml
and web.xml
files to reflect the version change.
Injecting an interface instead of concrete class MyBean doesn't work either.
Maybe i missed some mandatory configurtion changes. But currently i'm out of ideas.
Update:
My beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://jakarta.ee/xml/ns/jakartaee"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/beans_4_0.xsd"
version="4.0"
bean-discovery-mode="all">
</beans>
The only relevant change I can think of is that in EE 10, there was a behaviour change if you have an empty beans.xml. In EE 9 (CDI 3.0), an empty beans.xml is equivalent to bean-discovery-mode=all
whereas in EE 10 (CDI 4.0) it is equivalent to bean-discovery-mode=annotated
.
Based on the fact that you're not getting an error but myBean
is null
, I suspect that MyFactory
is not being picked up as a CDI bean and therefore injection is not taking place.
Can you check:
MyFactory
, is there a beans.xml? If so, is it blank? If not, what value does it set for bean-discovery-mode
?@Dependent
(or another bean defining annotation like @ApplicationScoped
) to MyFactory
fix the issue?