Question

I'm in the middle of porting a JSF 2.1 application to Jboss EAP 6.1 (JBoss AS 7.2). The application runs smoothly on Glassfish 3.1, and Weblogic 12c. Moreover a slightly similar application was ported successfully. The problem occurs in a specific EJB singleton. In this, I have a method with @PostConstruct annotation, which runs at startup and fills a List with SelectItems. During deploy, a java.lang.ClassNotFoundException exception is thrown, which says JBoss can't find the javax.faces.model.SelectItem class. If I comment out the method, everything is fine. The SelectItem class is used in some other beans in the web module without any problem.

My question is: Is there any known reason for this behaviour? Do I need some special configuration to use classes from the javax.faces package in an EJB module, running on JBoss? JSF is not packaged with the EAR, so the application uses the server's implementation.

Thank you!

Was it helpful?

Solution

You've there a design mistake. The business service (EJB) tier is not supposed to have any web (JSF) tier related dependencies. Having javax.faces.* imports in an EJB class is in first place already wrong. It makes the business service unreusable across different web tiers such as JAX-RS, Wicket, Struts, plain servlets, etc. In well designed application servers the unability to reach web tier classes from the EJB tier on is already enforced by (Java EE default) restrictions in classloaders.

Keep the EJB free of JSF dependencies. Perform the desired job in an eagerly initialized application scoped JSF managed bean instead.

@ManagedBean(eager=true)
@ApplicationScoped
public class App {

    private List<SelectItem> someItems;

    @EJB
    private AppService service;

    @PostConstruct
    public void init() {
        // Populate your List<SelectItem> here.
    }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top