1

When I changed my managedbean from requestscoped to sessionscoped it gives this error when deploying the app. Can anyone explain what is happening?

Does the ejb injection fails in the postconstruct? Also when changing it back to requestscoped I get the same error. When restarting NetBeans the requestscoped works.

SEVERE: ContainerBase.addChild: start: 
org.apache.catalina.LifecycleException: java.lang.IllegalArgumentException: javax.servlet.ServletException: com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class: class org.glassfish.webservices.WSServletContextListener
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:5332)
    at com.sun.enterprise.web.WebModule.start(WebModule.java:498)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:917)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:901)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:733)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2018)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1669)
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:109)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
    at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
    at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
    at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
    at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
    at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
    at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
    at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.IllegalArgumentException: javax.servlet.ServletException: com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class: class org.glassfish.webservices.WSServletContextListener
    at org.apache.catalina.core.StandardContext.addListener(StandardContext.java:2743)
    at org.apache.catalina.core.StandardContext.addApplicationListener(StandardContext.java:1966)
    at com.sun.enterprise.web.TomcatDeploymentConfig.configureApplicationListener(TomcatDeploymentConfig.java:235)
    at com.sun.enterprise.web.TomcatDeploymentConfig.configureWebModule(TomcatDeploymentConfig.java:94)
    at com.sun.enterprise.web.WebModuleContextConfig.start(WebModuleContextConfig.java:274)
    at com.sun.enterprise.web.WebModuleContextConfig.lifecycleEvent(WebModuleContextConfig.java:172)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:149)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:5329)
    ... 39 more
Caused by: javax.servlet.ServletException: com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class: class org.glassfish.webservices.WSServletContextListener
    at org.apache.catalina.core.StandardContext.createListener(StandardContext.java:2853)
    at org.apache.catalina.core.StandardContext.loadListener(StandardContext.java:4806)
    at com.sun.enterprise.web.WebModule.loadListener(WebModule.java:1599)
    at org.apache.catalina.core.StandardContext.addListener(StandardContext.java:2740)
    ... 46 more
Caused by: com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class: class org.glassfish.webservices.WSServletContextListener
    at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.createManagedObject(InjectionManagerImpl.java:315)
    at com.sun.enterprise.web.WebContainer.createListenerInstance(WebContainer.java:761)
    at com.sun.enterprise.web.WebModule.createListenerInstance(WebModule.java:1987)
    at org.apache.catalina.core.StandardContext.createListener(StandardContext.java:2851)
    ... 49 more
Caused by: java.lang.NullPointerException
    at com.sun.enterprise.container.common.impl.managedbean.ManagedBeanManagerImpl.createManagedBean(ManagedBeanManagerImpl.java:477)
    at com.sun.enterprise.container.common.impl.managedbean.ManagedBeanManagerImpl.createManagedBean(ManagedBeanManagerImpl.java:420)
    at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.createManagedObject(InjectionManagerImpl.java:299)
    ... 52 more

WARNING: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.IllegalArgumentException: javax.servlet.ServletException: com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class: class org.glassfish.webservices.WSServletContextListener
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.IllegalArgumentException: javax.servlet.ServletException: com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class: class org.glassfish.webservices.WSServletContextListener
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:921)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:901)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:733)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2018)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1669)
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:109)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
    at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
    at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
    at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
    at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
    at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
    at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
    at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:680)

SEVERE: Exception while invoking class com.sun.enterprise.web.WebApplication start method
java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.IllegalArgumentException: javax.servlet.ServletException: com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class: class org.glassfish.webservices.WSServletContextListener
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:138)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
    at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
    at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
    at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
    at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
    at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
    at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
    at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:680)

The bean:

package Controllers;

import Domain.Device;
import Domain.Employee;
import Domain.Tags;
import Service.CompanyFacade;
import Service.DeviceFacade;
import Service.EmployeeFacade;
import java.util.*;
import javax.annotation.PostConstruct;
import javax.inject.Named;
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;
import javax.inject.Inject;


@Named(value = "employeeController")
@RequestScoped
public class EmployeeController {
    @Inject
    private EmployeeFacade employeeFacade;
    @Inject
    private CompanyFacade companyFacade;
    @Inject
    private DeviceFacade deviceFacade;

    private Employee selectedEmployee;

    private String emptyMessage;

    private Long    employeeID;
    private String  firstNameOld;
    private String  firstNameNew;
    private String  insertionOld;
    private String  insertionNew;
    private String  lastNameOld;
    private String  lastNameNew;
    private String  functionNameNew;
    private String  functionNameOld;
    private String  emailNew;
    private String  emailOld;

    private List<Employee> employees;

    /**
     * Creates a new instance of EmployeeController
     */
    public EmployeeController() {
        this.emptyMessage = "Er zijn geen werknemers gevonden.";        
    }

    @PostConstruct
    public void init(){
        String user = FacesContext.getCurrentInstance()
                .getExternalContext()
                .getRemoteUser();
        Long companyID = null;
        System.out.println("user: " + user);
        try{
            companyID = this.companyFacade.getCompanyIDByUser(user);
        }
        catch(NullPointerException ex){
            FacesContext.getCurrentInstance().addMessage(null, 
                    new FacesMessage(FacesMessage.SEVERITY_ERROR, 
                    "Kan geen werknemers vinden.", ""));
        }
        System.out.println(companyID);
        if (companyID == null) {
            this.employees = new ArrayList<Employee>();
        }else{
            this.employees = (List<Employee>) this.employeeFacade.getAllByCompany(companyID);
        }
    }

    public Collection<Employee> getEmployees(){
        return this.employees;
    }

    public Collection<Tags> getTags(){
       return this.employeeFacade.getTags(1L, 1L);
    }

    public Collection<Device> getDevices(){
        return new ArrayList<Device>();
    }

    public String getEmptyMessage() {
        return emptyMessage;
    }

    public void firstNameChanged(ValueChangeEvent event) {
        System.out.println("firstNameChanged called.");
        this.firstNameOld = event.getOldValue().toString();
        this.firstNameNew = event.getNewValue().toString();
        //FacesContext context = FacesContext.getCurrentInstance();
        //Employee emp = context.getApplication().evaluateExpressionGet(context, "#{emp}", Employee.class);
        this.employeeID = this.selectedEmployee.getId();
    }

    public void insertionChanged(ValueChangeEvent event){
        this.insertionOld = event.getOldValue().toString();
        this.insertionNew = event.getNewValue().toString();
      //  FacesContext context = FacesContext.getCurrentInstance();
     //   Employee emp = context.getApplication().evaluateExpressionGet(context, "#{emp}", Employee.class);
        this.employeeID = this.selectedEmployee.getId();
    }

    public void lastNameChanged(ValueChangeEvent event){
        this.lastNameOld = event.getOldValue().toString();
        this.lastNameNew = event.getNewValue().toString();
      //  FacesContext context = FacesContext.getCurrentInstance();
      //  Employee emp = context.getApplication().evaluateExpressionGet(context, "#{emp}", Employee.class);
        this.employeeID = this.selectedEmployee.getId();
    }

    public void emailChanged(ValueChangeEvent event){
        this.emailOld = event.getOldValue().toString();
        this.emailNew = event.getNewValue().toString();
     //   FacesContext context = FacesContext.getCurrentInstance();
       // Employee emp = context.getApplication().evaluateExpressionGet(context, "#{emp}", Employee.class);
        this.employeeID = this.selectedEmployee.getId();
    }

    public void functionNameChanged(ValueChangeEvent event){
        this.functionNameOld = event.getOldValue().toString();
        this.functionNameNew = event.getNewValue().toString();
  //      FacesContext context = FacesContext.getCurrentInstance();
    //    Employee emp = context.getApplication().evaluateExpressionGet(context, "#{emp}", Employee.class);
        this.employeeID = this.selectedEmployee.getId();
    }

    public void saveName(){
        System.out.println("saveName called.");
        if(this.firstNameNew == null || this.firstNameOld == null){

        }
        else if(!this.firstNameNew.equals(this.firstNameOld)){
            if (this.employeeID != null) {
                Employee emp = this.employeeFacade.getByID(this.employeeID);
                emp.setFirstName(this.firstNameNew);
                this.employeeFacade.edit(emp);
                this.employeeID = null;
                this.firstNameNew = null;
                this.firstNameOld = null;
            }
        }
    }

    public void saveInsertion(){
        if(this.insertionNew == null || this.insertionOld == null){

        }
        else if(!this.insertionNew.equals(this.insertionOld)){
            if (this.employeeID != null) {
                Employee emp = this.employeeFacade.getByID(this.employeeID);
                emp.setInsertion(this.insertionNew);

                this.employeeFacade.edit(emp);
                this.employeeID = null;
                this.insertionNew = null;
                this.insertionOld = null;
            }
        }
    }

    public void saveLastName(){
        if(this.lastNameNew == null || this.lastNameOld == null){

        }
        else if(!this.lastNameNew.equals(this.lastNameOld)){
            if (this.employeeID != null) {
                Employee emp = this.employeeFacade.getByID(this.employeeID);
                emp.setLastName(this.lastNameNew);
                this.employeeFacade.edit(emp);
                this.employeeID = null;
                this.lastNameNew = null;
                this.lastNameOld = null;
            }
        }
    }

    public void saveFunctionName(){
        if(this.functionNameNew == null || this.functionNameOld == null){

        }
        else if(!this.functionNameNew.equals(this.functionNameOld)){
            if (this.employeeID != null) {
                Employee emp = this.employeeFacade.getByID(this.employeeID);
                emp.setFunctionName(this.functionNameNew);
                this.employeeFacade.edit(emp);
                this.employeeID = null;
                this.functionNameNew = null;
                this.functionNameOld = null;
            }
        }
    }

    public void saveEmail(){
        if(this.emailNew == null || this.emailOld == null){

        }
        else if(!this.emailNew.equals(this.emailOld)){
            if (this.employeeID != null) {
                Employee emp = this.employeeFacade.getByID(this.employeeID);
                emp.setEmail(this.emailNew);
                this.employeeFacade.edit(emp);
                this.employeeID = null;
                this.emailNew = null;
                this.emailOld = null;
            }
        }
    }

    public void cancel(){
        this.employeeID = null;
    }

    public Employee getSelectedEmployee() {
        return selectedEmployee;
    }

    public void setSelectedEmployee(Employee selectedEmployee) {
        System.out.println("setEmp: " + selectedEmployee.toString());
        this.selectedEmployee = selectedEmployee;
    }
Klaasvaak
  • 5,634
  • 15
  • 45
  • 68

1 Answers1

0

It always depends on the scope of the objects you inject into your bean. If one the following objects you inject: EmployeeFacade, CompanyFacade or DeviceFacade has a smaller scope, it will fail. In other words, you can only inject a bean with the same or a higher scope. I never tried this: request scoped property in session scoped JSF bean but it may help you out if you want to inject a smaller scoped object.

Community
  • 1
  • 1
fostiguy
  • 63
  • 6