0

I have such dependencies:

<dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
    </dependency>

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

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

And managed bean:

@ManagedBean(eager = true)
@ApplicationScoped
public class AppBean implements Serializable{
    private List<SelectItem> someEntitySI = null;

    @PostConstruct
    public void init(){
       try {
            someEntitySI = new ArrayList<SelectItem>();
            List<SomeEntity> types = Factory.getInstance().getSomeEntityDAO().getAllSomeEntities();
            for(SomeEntity type : types) {
                someEntitySI .add(new SelectItem(someEntity.getId(), someEntity.getName()));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } 
    }

When I deployed this on Tomcat @PostConstruct called, but when I deployed the same code on Glassfish(v4.1) the @PostConstruct don't work. Why so?

katch
  • 1
  • 1
  • 1
    People aren't mindreaders. You need to specify the meaning of "it works" and describe the results that lead you to conclude it "don't work". – Rob Feb 28 '15 at 12:46

1 Answers1

-1

If you are as dunny as I'm, and your web.xml starts like:

<web-app>
 ....
</web-app>

then you need to edit it:

<web-app 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/web-app_3_1.xsd"
     version="3.1">
     ....
     </web-app>

and after @PostConstrcut annotation will work on Glassfish. P.S. I'm still not totally sure why both wariants work on Tomcat.

katch
  • 1
  • 1