login.xhtml:请求的资源不可用

时间:2013-06-14 17:41:59

标签: jsf tomcat jpa primefaces apache-tomee

我在Eclipse中创建了一个Dyamic Web项目来尝试http://www.simtay.com/simple-crud-web-application-with-jsf-2-1-primefaces-3-5-maven-and-jpa/示例的登录部分 我在项目属性中启用的项目构面是:

  • CDI
  • 动态网络模块
  • 爪哇
  • 的JavaScript
  • JavaServerFaces
  • JPA

作为容器我使用TomEE。

当我尝试启动login.xhtml页面时,我获得了

HTTP Status 404 - /LAI_pezzi_Login/faces/Login.xhtml

type Status report

message /LAI_pezzi_Login/faces/Login.xhtml

description The requested resource is not available.

Apache Tomcat (TomEE)/7.0.37

TomEE控制台:

SEVERE: StandardWrapper.Throwable
java.lang.IllegalStateException: No Factories configured for this Application. This happens if the faces-initialization does not work at all - make sure that you properly include all configuration settings necessary for a basic faces application and that all the necessary libs are included. Also check the logging output of your web application and your container for any exceptions!
If you did that and find nothing, the mistake might be due to the fact that you use some special web-containers which do not support registering context-listeners via TLD files and a context listener is not setup in your web.xml.
A typical config looks like this;
<listener>
  <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>

    at javax.faces.FactoryFinder._getFactory(FactoryFinder.java:286)
    at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:206)
    at javax.faces.webapp.FacesServlet.init(FacesServlet.java:116)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5033)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5317)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    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:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)

giu 14, 2013 5:17:59 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /PrimeFaces_DataTable_DB_editable threw load() exception
java.lang.IllegalStateException: No Factories configured for this Application. This happens if the faces-initialization does not work at all - make sure that you properly include all configuration settings necessary for a basic faces application and that all the necessary libs are included. Also check the logging output of your web application and your container for any exceptions!
If you did that and find nothing, the mistake might be due to the fact that you use some special web-containers which do not support registering context-listeners via TLD files and a context listener is not setup in your web.xml.
A typical config looks like this;
<listener>
  <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>

    at javax.faces.FactoryFinder._getFactory(FactoryFinder.java:286)
    at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:206)
    at javax.faces.webapp.FacesServlet.init(FacesServlet.java:116)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5033)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5317)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    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:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)

giu 14, 2013 5:17:59 PM org.apache.tomee.catalina.TomcatWebAppBuilder init
INFO: ------------------------- localhost -> /LAI_pezzi_Login
giu 14, 2013 5:17:59 PM org.apache.tomee.catalina.TomEEClassLoaderEnricher validateJarFile
WARNING: jar '/home/caterpillar/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/LAI_pezzi_Login/WEB-INF/lib/javax.persistence_1.0.0.jar' contains offending class: javax.persistence.Entity. It will be ignored.
giu 14, 2013 5:18:00 PM org.apache.openejb.config.ConfigurationFactory configureApplication
INFO: Configuring enterprise application: /home/caterpillar/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/LAI_pezzi_Login
giu 14, 2013 5:18:00 PM org.apache.openejb.config.ConfigurationFactory configureService
INFO: Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
giu 14, 2013 5:18:00 PM org.apache.openejb.config.AutoConfig createContainer
INFO: Auto-creating a container for bean LAI_pezzi_Login.Comp1241762921: Container(type=MANAGED, id=Default Managed Container)
giu 14, 2013 5:18:00 PM org.apache.openejb.assembler.classic.Assembler createRecipe
INFO: Creating Container(id=Default Managed Container)
giu 14, 2013 5:18:00 PM org.apache.openejb.core.managed.SimplePassivater init
INFO: Using directory /tmp for stateful session passivation
giu 14, 2013 5:18:00 PM org.apache.openejb.config.AutoConfig deploy
INFO: Configuring PersistenceUnit(name=LAI_pezzi_Login)
giu 14, 2013 5:18:00 PM org.apache.openejb.config.AutoConfig setJtaDataSource
INFO: Adjusting PersistenceUnit LAI_pezzi_Login <jta-data-source> to Resource ID 'My DataSource' from 'null'
giu 14, 2013 5:18:00 PM org.apache.openejb.config.AutoConfig setNonJtaDataSource
INFO: Adjusting PersistenceUnit LAI_pezzi_Login <non-jta-data-source> to Resource ID 'My Unmanaged DataSource' from 'null'
giu 14, 2013 5:18:00 PM org.apache.openejb.config.AppInfoBuilder build
INFO: Enterprise application "/home/caterpillar/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/LAI_pezzi_Login" loaded.
giu 14, 2013 5:18:00 PM org.apache.openejb.assembler.classic.Assembler createApplication
INFO: Assembling app: /home/caterpillar/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/LAI_pezzi_Login
giu 14, 2013 5:18:02 PM null
INFO: You have enabled runtime enhancement, but have not specified the set of persistent classes.  OpenJPA must look for metadata for every loaded class, which might increase class load times significantly.
giu 14, 2013 5:18:03 PM null
INFO: OpenJPA dynamically loaded a validation provider.
giu 14, 2013 5:18:03 PM org.apache.openejb.assembler.classic.ReloadableEntityManagerFactory createDelegate
INFO: PersistenceUnit(name=LAI_pezzi_Login, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) - provider time 2951ms
giu 14, 2013 5:18:03 PM org.apache.openejb.cdi.CdiBuilder initSingleton
INFO: Existing thread singleton service in SystemInstance(): org.apache.openejb.cdi.ThreadSingletonServiceImpl@3f894493
giu 14, 2013 5:18:03 PM org.apache.openejb.cdi.OpenEJBLifecycle startApplication
INFO: OpenWebBeans Container is starting...
giu 14, 2013 5:18:03 PM org.apache.webbeans.plugins.PluginLoader startUp
INFO: Adding OpenWebBeansPlugin : [CdiPlugin]
giu 14, 2013 5:18:03 PM org.apache.webbeans.plugins.PluginLoader startUp
INFO: Adding OpenWebBeansPlugin : [OpenWebBeansJsfPlugin]
giu 14, 2013 5:18:03 PM org.apache.openejb.cdi.BeansDeployer validateInjectionPoints
INFO: All injection points are validated successfully.
giu 14, 2013 5:18:03 PM org.apache.openejb.cdi.OpenEJBLifecycle startApplication
INFO: OpenWebBeans Container has started, it took 23 ms.
giu 14, 2013 5:18:03 PM org.apache.openejb.assembler.classic.Assembler createApplication
INFO: Deployed Application(path=/home/caterpillar/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/LAI_pezzi_Login)
giu 14, 2013 5:18:04 PM org.apache.catalina.core.StandardContext addApplicationListener
INFO: The listener "org.apache.myfaces.webapp.StartupServletContextListener" is already configured for this context. The duplicate definition has been ignored.
giu 14, 2013 5:18:04 PM org.apache.myfaces.config.DefaultFacesConfigurationProvider getStandardFacesConfig
INFO: Reading standard config META-INF/standard-faces-config.xml
giu 14, 2013 5:18:04 PM org.apache.myfaces.config.DefaultFacesConfigurationProvider getWebAppFacesConfig
INFO: Reading config /WEB-INF/faces-config.xml
giu 14, 2013 5:18:04 PM org.apache.myfaces.config.DefaultFacesConfigurationProvider getClassloaderFacesConfig
INFO: Reading config : jar:file:/home/caterpillar/Universita/Programmazione/apache-tomee-plus-1.5.2/lib/openwebbeans-jsf-1.1.8.jar!/META-INF/faces-config.xml
giu 14, 2013 5:18:04 PM org.apache.myfaces.config.LogMetaInfUtils logArtifact
INFO: Artifact 'myfaces-api' was found in version '2.1.10' from path 'file:/home/caterpillar/Universita/Programmazione/apache-tomee-plus-1.5.2/lib/myfaces-api-2.1.10.jar'
giu 14, 2013 5:18:04 PM org.apache.myfaces.config.LogMetaInfUtils logArtifact
INFO: Artifact 'myfaces-impl' was found in version '2.1.10' from path 'file:/home/caterpillar/Universita/Programmazione/apache-tomee-plus-1.5.2/lib/myfaces-impl-2.1.10.jar'
giu 14, 2013 5:18:05 PM org.apache.myfaces.util.ExternalSpecifications isBeanValidationAvailable
INFO: MyFaces Bean Validation support enabled
giu 14, 2013 5:18:05 PM org.apache.myfaces.application.ApplicationImpl getProjectStage
INFO: Couldn't discover the current project stage, using Production
giu 14, 2013 5:18:05 PM org.apache.myfaces.config.FacesConfigurator handleSerialFactory
INFO: Serialization provider : class org.apache.myfaces.shared_impl.util.serial.DefaultSerialFactory
giu 14, 2013 5:18:05 PM org.apache.myfaces.config.annotation.DefaultLifecycleProviderFactory getLifecycleProvider
INFO: Using LifecycleProvider org.apache.myfaces.config.annotation.Tomcat7AnnotationLifecycleProvider
giu 14, 2013 5:18:05 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.apache.myfaces.webapp.StartupServletContextListener
java.lang.LinkageError: loader (instance of  sun/misc/Launcher$ExtClassLoader): attempted  duplicate class definition for name: "com/sun/crypto/provider/DESKeyGenerator"
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at java.security.Provider$Service.getImplClass(Provider.java:1279)
    at java.security.Provider$Service.newInstance(Provider.java:1237)
    at javax.crypto.KeyGenerator.nextSpi(KeyGenerator.java:328)
    at javax.crypto.KeyGenerator.<init>(KeyGenerator.java:157)
    at javax.crypto.KeyGenerator.getInstance(KeyGenerator.java:207)
    at org.apache.myfaces.shared.util.StateUtils.findSecret(StateUtils.java:887)
    at org.apache.myfaces.shared.util.StateUtils.findSecret(StateUtils.java:876)
    at org.apache.myfaces.shared.util.StateUtils.initSecret(StateUtils.java:781)
    at org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces(AbstractFacesInitializer.java:148)
    at org.apache.myfaces.webapp.StartupServletContextListener.contextInitialized(StartupServletContextListener.java:119)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    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:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)

giu 14, 2013 5:18:05 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
giu 14, 2013 5:18:05 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/LAI_pezzi_Login] startup failed due to previous errors
giu 14, 2013 5:18:05 PM org.apache.openejb.assembler.classic.Assembler destroyApplication
INFO: Undeploying app: /home/caterpillar/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/LAI_pezzi_Login
giu 14, 2013 5:18:06 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-9080"]
giu 14, 2013 5:18:06 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-9009"]
giu 14, 2013 5:18:06 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 21399 ms

我知道代码必须适应我的需要,但网页本身至少应该开始(并且当你触发按钮时必须失败) 以下是最重要的文件和完整的文件列表:

Login.xhtml

<ui:composition template="/templates/layout.xhtml"
     xmlns="http://www.w3.org/1999/xhtml"
     xmlns:f="http://java.sun.com/jsf/core"
     xmlns:h="http://java.sun.com/jsf/html"
     xmlns:ui="http://java.sun.com/jsf/facelets"
     xmlns:p="http://primefaces.org/ui"
>
     <ui:define name="content">
         <h:form styleClass="loginPanelStyle">
                 <p:growl id="msgs" showDetail="true" sticky="false" />                        
                <p:panelGrid columns="2">
                <f:facet name="header">
                    Login Panel
                </f:facet>
                <h:outputText value="Username : "></h:outputText>
                <p:inputText id="username" value="#{loginController.username}" required="true" requiredMessage="Please Enter Username!" message="fc">
                    <f:validateLength minimum="1" />  
                </p:inputText>
                <h:outputText value="Password : "></h:outputText>
                <p:password id="password" value="#{loginController.password}" required="true" requiredMessage="Please Enter password!">
                    <f:validateLength minimum="1" />  
                </p:password>
                <f:facet name="footer">
                <p:commandButton value="Submit" update="msgs" actionListener="#{loginController.login}" type="submit" icon="ui-icon-check" style="margin:0"></p:commandButton>
                </f:facet> 
            </p:panelGrid>
        </h:form>
     </ui:define>
</ui:composition>

LoginController.java

package controller;


import util.DateUtility;
import java.io.IOException;
import java.io.Serializable;
import java.security.Principal;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Login Controller class allows only authenticated users to log in to the web application. 
 * @author Emre Simtay <emre@simtay.com>
 */

@Named
@SessionScoped
public class LoginController implements Serializable {
    @Inject
    private transient Logger logger;
    private String username;
    private String password;

    /** Creates a new instance of LoginController */
    public LoginController(){
    }

    //  Getters and Setters

    /** 
     * @return username
     */
    public String getUsername() {
            return username;
    }

    /**
     *
     * @param username
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     *
     * @return  password
     */
    public String getPassword() {
    return password;
    }

    /**
     *
     * @param password
     */
    public void setPassword(String password) {
    this.password = password;
    }

    /**
     * Listen for button clicks on the #{loginController.login} action, 
     * validates the username and password entered by the user and
     * navigates to the appropriate page.
     * @param actionEvent 
     */
    public void login(ActionEvent actionEvent){

        FacesContext context = FacesContext.getCurrentInstance();  
        HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();                
        try {
                String navigateString = "";
                // Checks if username and password are valid if not throws a ServletException
                request.login(username, password);
                // gets the user principle and navigates to the appropriate page
                Principal principal = request.getUserPrincipal();
                if(request.isUserInRole("Administrator")){
                        navigateString = "/admin/AdminHome.xhtml";
                }else if(request.isUserInRole("Manager")){
                        navigateString = "/manager/ManagerHome.xhtml";
                }else if(request.isUserInRole("User")){
                        navigateString = "/user/UserHome.xhtml";
                }
                try {
                    logger.log(Level.INFO, "User ({0}) loging in #" +DateUtility.getCurrentDateTime(), request.getUserPrincipal().getName());
                    context.getExternalContext().redirect(request.getContextPath() + navigateString);
                } catch (IOException ex) {
                    logger.log(Level.SEVERE, "IOException, Login Controller" + "Username : " + principal.getName(), ex);
                    context.addMessage(null, new FacesMessage("Error!", "Exception occured")); 
                }
        } catch (ServletException e) {
                logger.log(Level.SEVERE, "IOException, Login Controller: The username or password you provided does not match our records.");
                context.addMessage(null, new FacesMessage("Error!", "The username or password you provided does not match our records."));                        
        }
    }

    /**
     * Listen for logout button clicks on the #{loginController.logout} action
     * and navigates to login screen.
     */
    public void logout(){

        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        logger.log(Level.INFO, "User ({0}) loging out #" +DateUtility.getCurrentDateTime(), request.getUserPrincipal().getName());
        if(session != null){
            session.invalidate();
        }
        FacesContext.getCurrentInstance().getApplication().getNavigationHandler().handleNavigation(FacesContext.getCurrentInstance(), null, "/Login.xhtml?faces-redirect=true");
    }

}

文件列表:

ls -R
.:
build  src  WebContent

./build:
classes

./build/classes:
controller  META-INF  util

./build/classes/controller:
LoginController.class

./build/classes/META-INF:
persistence.xml

./build/classes/util:
DateUtility.class

./src:
controller  META-INF  util

./src/controller:
LoginController.java

./src/META-INF:
persistence.xml

./src/util:
DateUtility.java

./WebContent:
ErrorAccessDenied.xhtml  Login.xhtml  META-INF  resources  WEB-INF

./WebContent/META-INF:
MANIFEST.MF

./WebContent/resources:
css  primefaces-nz

./WebContent/resources/css:
default.css

./WebContent/resources/primefaces-nz:
images  theme.css

./WebContent/resources/primefaces-nz/images:
ui-bg_flat_30_cccccc_40x100.png           ui-bg_highlight-soft_35_222222_1x100.png  ui-icons_292cd1_256x240.png
ui-bg_flat_50_5c5c5c_40x100.png           ui-bg_highlight-soft_44_444444_1x100.png  ui-icons_a83300_256x240.png
ui-bg_glass_40_ffc73d_1x400.png           ui-bg_highlight-soft_80_1442c8_1x100.png  ui-icons_cccccc_256x240.png
ui-bg_highlight-hard_20_16475f_1x100.png  ui-bg_inset-hard_30_dedede_1x100.png      ui-icons_ffffff_256x240.png
ui-bg_highlight-soft_33_1258bf_1x100.png  ui-icons_222222_256x240.png

./WebContent/WEB-INF:
beans.xml  faces-config.xml  lib  web.xml

./WebContent/WEB-INF/lib:

P.S。在TomEE和项目文件中都有库有问题吗?我被迫这样做,因为当我使用Tomcat时,我错过了很多库,我不知道从哪里得到它们,然后我搬到了TomEE

1 个答案:

答案 0 :(得分:2)

webapp的运行时类路径很乱。 webapp的/WEB-INF/lib似乎包含JSF和JPA库,它们已经已经由TomEE自身提供为符合Java EE Web配置文件的容器。

Tomcat是一个准系统JSP / Servlet容器,因此不附带例如JSF,JPA,EJB等。这正是您需要手动提供和配置JSF,JPA,EJB等以及Tomcat的webapp的原因。但是对于TomEE(以及Glassfish,JBoss AS等)来说,这绝对不是必需的,并且只会因为运行时类路径中重复的不同版本化库而最终导致类加载冲突。

删除/WEB-INF/lib中已由目标容器本身提供的库。