@RequestScoped gives Runtime Exception.

Asked 2 years ago, Updated 2 years ago, 147 views

[Event]
I write a program where I enter my number and name from the screen and display it on the console, but when I run it, it becomes RuntimeException and I can't open the screen.


[Tries]

I deleted @RequestScoped from the backing bean (MeiboBean.java) and tried to run it, and I was able to see the screen.Therefore, I think it is probably because I wrote the @RequestScoped annotation, but I don't think the writing is wrong.
I tried not to use import on this site, but it still didn't work.

Environment

  • Browser:IE
  • Integrated Development Environment: NetBeans
  • server runtime:classfish

[source code]

package bean;

import javax.enterprise.context.RequestScoped;
import javax.inject.Named;


@Named
@RequestScoped
public class MeiboBean {
    private Integer number;
    private String name;

    public void to Console() {
        System.out.println("number="+this.number+"/name="+this.name);
    }

    public Integer getNumber() {
        return number;
    }

    public void setNumber (Integer number) {
        This.number = number;
    }

    public String getName() {
        return name;
    }

    public void setName(String name){
        this.name = name;
    }    
}


<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html">
    <h:head>
        <title>Sample01</title>
    </h:head>
    <h:body>
        <h2>Create list data</h2>
        <h:form>
            Number: <h:inputText value="#{meiboBean.number}"/>br/>
            Name: <h:inputText value="#{meiboBean.name}"/>br/>
            <h:commandButton value="Send" actionListener="#{meiboBean.toConsole()}"/>
        </h:form>

    </h:body>
</html>


java.lang.RuntimeException: 
    at bean.MeiboBean.<init> (MeiboBean.java:1)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.jboss.weld.injection.ConstructorInjectionPoint.newInstance(ConstructorInjectionPoint.java:119)
    at org.jboss.weld.injection.ConstructorInjectionPoint.invokeAroundConstructCallbacks (ConstructorInjectionPoint.java:92)
    at org.jboss.weld.injection.ConstructorInjectionPoint.newInstance(ConstructorInjectionPoint.java:78)
    at org.jboss.weld.injection.producer.AbstractInstantiator.newInstance(AbstractInstantiator.java:28)
    at org.jboss.weld.injection.producer.BasicInjectionTarget.produce (BasicInjectionTarget.java:112)
    at org.jboss.weld.injection.producer.BeanInjectionTarget.produce (BeanInjectionTarget.java:180)
    at org.jboss.weld.bean.ManagedBean.create (ManagedBean.java:158)
    at org.jboss.weld.contexts.AbstractContext.get (AbstractContext.java:96)
    at org.jboss.weld.bean.ContextualInstanceStratey$DefaultContextualInstanceStratey.get (ContextualInstanceStratey.java:100)
    at org.jboss.weld.bean.ContextualInstanceStratey$CachingContextualInstanceStratey.get (ContextualInstanceStratey.java:177)
    at org.jboss.weld.bean.ContextualInstance.get (ContextualInstance.java:50)
    at org.jboss.weld.manager.BeanManagerImpl.getReference (BeanManagerImpl.java:676)
    at org.jboss.weld.module.web.el.AbstractWeldELResolver.lookup (AbstractWeldELResolver.java:107)
    at org.jboss.weld.module.web.el.AbstractWeldELResolver.getValue (AbstractWeldELResolver.java:90)
    at javax.el.CompositeELResolver.getValue (CompositeELResolver.java:147)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue (DemuxCompositeELResolver.java:156)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue (DemuxCompositeELResolver.java:184)
    at com.sun.el.parser.AstIdentifier.getValue (AstIdentifier.java:92)
    at com.sun.el.parser.AstValue.getBase(AstValue.java:126)
    at com.sun.el.parser.AstValue.getValue (AstValue.java:175)

java java-ee annotations

2022-09-30 14:57

1 Answers

How many versions are there?
The old version worked, but the new version worked unstable.

OK case)
NetBeans 8.02 (Java EE7)
JDK 1.7
JSF 2.2
Glassfish 4.1

NG case) Same as above
12(EE7 or EE8)
JDK 1.7, 1.8, 11
JSF 2.2, 2.3
Glassfish 5.1

*By the way, if you don't write a RequestScope, you can't connect with bean(CDI).
This is the message that instance generation has failed when you inject when you display the page.


2022-09-30 14:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.