0

My IDE indicates ManagedBean as depricated. I have read about this and decided to replace my javax.faces.bean.ManagedBean annotations to javax.inject.Named. But when replaced, my CDI Bean is not recognized (PostConstruct is not called):

//@ManagedBean(name = "carlistbean")
@Named(value = "carlistbean")
@SessionScoped
public class CarListBean implements Serializable {

    @PostConstruct
    public void init(){
        cars = carRepository.getAllCars();
    }

    @Inject
    private CarRepository carRepository;

I am using the Bean as backend for my JSF Page:

<h:dataTable value = "#{carlistbean.cars}" var = "car"

I am on JSF 2.2.18

    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.2.18</version>
    </dependency>

    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.2.18</version>
    </dependency>

Can someone help me / give a hint ?

UPDATE

I am using J2ee 8

my beans.xml in WEB-INF looks like this:

<?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>
mcfly soft
  • 10,143
  • 21
  • 80
  • 162
  • 1
    Did you **also** replace the sessionscope with a cdi one? https://stackoverflow.com/questions/4347374/backing-beans-managedbean-or-cdi-beans-named – Kukeltje Feb 20 '19 at 08:06
  • Yes I also used javax.enterprise.context.SessionScoped. – mcfly soft Feb 20 '19 at 08:16
  • 2
    What is the Java EE version? And the application server? (how) did you ensure it's not using another jsf version? If you are on Java EE 6 do you have an empty beans.xml? Any warning on the app server's log? – perissf Feb 20 '19 at 08:39
  • 1
    or if you are on a newer Java EE version the right corresponding beans.xml content – Kukeltje Feb 20 '19 at 09:18
  • I have updated the info in the question. – mcfly soft Feb 20 '19 at 09:35
  • 2
    java ee 8 and in which server do you run? And java ee 8 is JSF 2.3, not 2.2. In addition your pom should not include the jsf jars but have the full java ee 8 API's as provided dependencies. – Kukeltje Feb 20 '19 at 10:49

0 Answers0