6

我有这个托管 bean:

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.sql.DataSource;
import javax.annotation.Resource;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
// or import javax.faces.bean.ManagedBean;   

import org.glassfish.osgicdi.OSGiService;

@Named("ApplicationController")
@SessionScoped

public class Tab1Page implements Serializable {
    public String actionString;

    public Tab1Page() {
    }
    public static final long serialVersionUID = 254415216070877770L;
// Constants
    public final static String hashKey = "tab1PageTab";
    public String actApplicationControllerionString = "";

    @PostConstruct
    public void post() {
        Format formatter;
        Date date = new Date();

        // Time formate 01:12:53 AM
        formatter = new SimpleDateFormat("hh:mm:ss a");
        tabName = formatter.format(date);
        System.out.println("Tab1Page\t" + tabName + "\t@PostConstruct...");
    }

    @PreDestroy
    public void destroy() {
        Format formatter;
        Date date = new Date();

        // Time formate 01:12:53 AM
        formatter = new SimpleDateFormat("hh:mm:ss a");
        tabName = formatter.format(date);
        System.out.println("Tab1Page\t" + tabName + "\t@PreDestroy...");
    }
    String tabName;

    public String getTabName() {
        return this.getClass().getName().substring(this.getClass().getName().lastIndexOf(".")) + "\t" + tabName;
    }

    public void setTabName(String tabName) {
        this.tabName = tabName;
    }

    public String getActionString() {
        String actionString = null;
        return actionString;
    }

    public void setActionString(String actionString) {
        this.actionString = actionString;
    }
}

当我尝试在 Glassfish 上部署它时,出现此错误:

[#|2012-04-16T21:42:51.689+0300|INFO|glassfish3.1.2|org.glassfish.osgiweb|_ThreadID=63;_ThreadName=Thread-2;|Removed bundle 416 against context path /HM_57-1.0-SNAPSHOT |#]

[#|2012-04-16T21:42:51.690+0300|WARNING|glassfish3.1.2|org.glassfish.osgijavaeebase|_ThreadID=63;_ThreadName=Thread-2;|Failed to deploy bundle com.DX_57.History-Module-57 [416]
org.glassfish.osgijavaeebase.DeploymentException: Deployment of com.DX_57.History-Module-57 [416] failed because of following reason: Failed while deploying bundle com.DX_57.History-Module-57 [416] : java.lang.RuntimeException: Failed to deploy bundle [ com.DX_57.History-Module-57 [416] ], root cause: Exception while loading the app
    at org.glassfish.osgijavaeebase.AbstractOSGiDeployer.deploy(AbstractOSGiDeployer.java:125)
    at org.glassfish.osgijavaeebase.OSGiContainer.deploy(OSGiContainer.java:154)
    at org.glassfish.osgijavaeebase.JavaEEExtender.deploy(JavaEEExtender.java:107)
    at org.glassfish.osgijavaeebase.JavaEEExtender.access$200(JavaEEExtender.java:61)
    at org.glassfish.osgijavaeebase.JavaEEExtender$HybridBundleTrackerCustomizer$1.call(JavaEEExtender.java:151)
    at org.glassfish.osgijavaeebase.JavaEEExtender$HybridBundleTrackerCustomizer$1.call(JavaEEExtender.java:148)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.RuntimeException: Failed to deploy bundle [ com.DX_57.History-Module-57 [416] ], root cause: Exception while loading the app
    at org.glassfish.osgijavaeebase.OSGiDeploymentRequest.deploy(OSGiDeploymentRequest.java:196)
    at org.glassfish.osgijavaeebase.OSGiDeploymentRequest.execute(OSGiDeploymentRequest.java:118)
    at org.glassfish.osgijavaeebase.AbstractOSGiDeployer.deploy(AbstractOSGiDeployer.java:121)
    ... 10 more
Caused by: org.glassfish.deployment.common.DeploymentException: WELD-000075 Normal scoped managed bean implementation class has a public field:  public@Named @SessionScoped class com.DX_57.HM_57.Tab1Page
    at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:181)
    at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:128)
    at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:277)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:460)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
    at org.glassfish.osgijavaeebase.OSGiDeploymentRequest.deploy(OSGiDeploymentRequest.java:183)
    ... 12 more
Caused by: org.jboss.weld.exceptions.DefinitionException: WELD-000075 Normal scoped managed bean implementation class has a public field:  public@Named @SessionScoped class com.DX_57.HM_57.Tab1Page
    at org.jboss.weld.bean.ManagedBean.checkBeanImplementation(ManagedBean.java:438)
    at org.jboss.weld.bean.AbstractClassBean.initialize(AbstractClassBean.java:191)
    at org.jboss.weld.bean.ManagedBean.initialize(ManagedBean.java:322)
    at org.jboss.weld.bootstrap.AbstractBeanDeployer.deploy(AbstractBeanDeployer.java:115)
    at org.jboss.weld.bootstrap.BeanDeployment.deployBeans(BeanDeployment.java:204)
    at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:344)
    at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:179)
    ... 17 more
|#]

我不明白这个错误是什么意思。我将所有方法修改为公开,但仍然出现此错误。我怎样才能更正代码?

最良好的祝愿

4

1 回答 1

14

问题是字段 ( public String actionString;) 而不是方法。

来自文档

如果托管 bean 具有公共字段,则它必须具有 @Dependent 范围。如果具有公共字段的托管 bean 声明了 @Dependent 以外的任何范围,则容器会自动检测到问题并将其视为定义错误。

于 2012-04-16T18:50:58.547 回答