Search code examples
jsfmojarrajsf-2.3

Mojarra 2.3.0-m06, @PersistenceContext field is null


I have such converter:

@FacesConverter(managed = true, value = "myConverter")
public class MyConverter implements Converter {
    @PersistenceContext(unitName = MyService.PERSISTENCE_NAME)
    private EntityManager entityManager;
    ...
}

The problem is that entityManager is null. faces-config JSF version is 2.3, Mojarra 2.3.0-m06 is used. In the Application#createConverter() implementation it jumps into the first if's body, but doesn't create the converter. entityManager is not null when the converter is a bean.


Solution

  • I needed to add a beans.xml file in the WEB-INF directory with the following content:

    <?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_1_1.xsd"
           bean-discovery-mode="all">
    </beans>