在 JBoss AS 6 和 JBoss AS 7 中部署简单 Web 应用程序时出现 404 错误?

404 Error while deploying simple web-app in JBoss AS 6 and JBoss AS 7?

我按照 this blogREST 层中注入 EJB

这是我尝试使用 Eclipse 在 JBOSS AS 6 和 7 中部署的代码:

REST:

package com.example.rest;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Stateless
@Path("current")
public class ServiceFacade {

    @EJB
    ServiceImpl service;

    @GET
    public String getDate(){
        return service.getCurrentDate().toString();
    }

}


EJB:

import java.util.Date;

import javax.ejb.Stateless;

@Stateless
public class ServiceImpl {

    public Date getCurrentDate(){
        return new Date();
    }

}

@ApplicationPath("rest")
public class RestApplication extends Application {
}

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.sample.rest</groupId>
  <artifactId>restejb</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <description>simplet project to test ejb injection in rest</description>
  <dependencies>
  <dependency>
      <groupId>org.jboss.spec</groupId>
      <artifactId>jboss-javaee-6.0</artifactId>
      <version>1.0.0.Final</version>
      <packaging>war</packaging>
      <type>pom</type>
      <scope>provided</scope>
    </dependency>
    </dependencies>
</project>

当我访问 http://localhost:8080/restejb/rest/current 时,我得到 404 page NOT found error

Here is the log from deployment to JBOSS AS 6:




  11:19:23,701 INFO  [AbstractJBossASServerBase] Server Configuration:

    JBOSS_HOME URL: file:/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/
    Bootstrap: $JBOSS_HOME/server/default/conf/bootstrap.xml
    Common Base: $JBOSS_HOME/common/
    Common Library: $JBOSS_HOME/common/lib/
    Server Name: default
    Server Base: $JBOSS_HOME/server/
    Server Library: $JBOSS_HOME/server/default/lib/
    Server Config: $JBOSS_HOME/server/default/conf/
    Server Home: $JBOSS_HOME/server/default/
    Server Data: $JBOSS_HOME/server/default/data/
    Server Log: $JBOSS_HOME/server/default/log/
    Server Temp: $JBOSS_HOME/server/default/tmp/

11:19:23,706 INFO  [AbstractServer] Starting: JBossAS [6.1.0.Final "Neo"]
11:19:27,412 INFO  [ServerInfo] Java version: 1.7.0_71,Oracle Corporation
11:19:27,412 INFO  [ServerInfo] Java Runtime: Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
11:19:27,413 INFO  [ServerInfo] Java VM: Java HotSpot(TM) 64-Bit Server VM 24.71-b01,Oracle Corporation
11:19:27,413 INFO  [ServerInfo] OS-System: Mac OS X 10.9.5,x86_64
11:19:27,414 INFO  [ServerInfo] VM arguments: -Dprogram.name=JBossTools: JBoss AS 6.x -Xms256m -Xmx768m -XX:MaxPermSize=256m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djava.endorsed.dirs=/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/lib/endorsed -Djava.library.path=/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/bin/native -Dlogging.configuration=file:/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/bin/logging.properties -Dfile.encoding=UTF-8 
11:19:27,483 INFO  [JMXKernel] Legacy JMX core initialized
11:19:35,849 INFO  [AbstractServerConfig] JBoss Web Services - Stack CXF Server 3.4.1.GA
11:19:36,679 INFO  [JSFImplManagementDeployer] Initialized 3 JSF configurations: [Mojarra-1.2, MyFaces-2.0, Mojarra-2.0]
11:19:47,865 WARNING [FileConfigurationParser] AIO wasn't located on this platform, it will fall back to using pure Java NIO. If your platform is Linux, install LibAIO to enable the AIO journal
11:19:48,389 INFO  [JMXConnector] starting JMXConnector on host localhost:1090
11:19:48,609 INFO  [MailService] Mail Service bound to java:/Mail
11:19:49,990 INFO  [HornetQServerImpl] live server is starting with configuration HornetQ Configuration (clustered=false,backup=false,sharedStore=true,journalDirectory=/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/server/default/data/hornetq/journal,bindingsDirectory=/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/server/default/data/hornetq/bindings,largeMessagesDirectory=/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/server/default/data/hornetq/largemessages,pagingDirectory=/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/server/default/data/hornetq/paging)
11:19:49,992 INFO  [HornetQServerImpl] Waiting to obtain live lock
11:19:50,105 INFO  [JournalStorageManager] Using NIO Journal
11:19:50,140 WARNING [HornetQServerImpl] Security risk! It has been detected that the cluster admin user and password have not been changed from the installation default. Please see the HornetQ user guide, cluster chapter, for instructions on how to do this.
11:19:50,468 INFO  [FileLockNodeManager] Waiting to obtain live lock
11:19:50,469 INFO  [FileLockNodeManager] Live Server Obtained live lock
11:19:51,283 INFO  [NettyAcceptor] Started Netty Acceptor version 3.2.3.Final-r${buildNumber} localhost:5445 for CORE protocol
11:19:51,287 INFO  [NettyAcceptor] Started Netty Acceptor version 3.2.3.Final-r${buildNumber} localhost:5455 for CORE protocol
11:19:51,290 INFO  [HornetQServerImpl] Server is now live
11:19:51,291 INFO  [HornetQServerImpl] HornetQ Server version 2.2.5.Final (HQ_2_2_5_FINAL_AS7, 121) [251821f6-c6bb-11e4-9df3-60334b2115c1] started
11:19:51,386 INFO  [WebService] Using RMI server codebase: http://localhost:8083/
11:19:51,699 INFO  [jbossatx] ARJUNA-32010 JBossTS Recovery Service (tag: JBOSSTS_4_14_0_Final) - JBoss Inc.
11:19:51,711 INFO  [arjuna] ARJUNA-12324 Start RecoveryActivators
11:19:51,745 INFO  [arjuna] ARJUNA-12296 ExpiredEntryMonitor running at Tue, 10 Mar 2015 11:19:51
11:19:51,903 INFO  [arjuna] ARJUNA-12310 Recovery manager listening on endpoint 127.0.0.1:4712
11:19:51,904 INFO  [arjuna] ARJUNA-12344 RecoveryManagerImple is ready on port 4712
11:19:51,905 INFO  [jbossatx] ARJUNA-32013 Starting transaction recovery manager
11:19:51,933 INFO  [arjuna] ARJUNA-12163 Starting service com.arjuna.ats.arjuna.recovery.ActionStatusService on port 4713
11:19:51,934 INFO  [arjuna] ARJUNA-12337 TransactionStatusManagerItem host: 127.0.0.1 port: 4713
11:19:51,937 INFO  [arjuna] ARJUNA-12170 TransactionStatusManager started on port 4713 and host 127.0.0.1 with service com.arjuna.ats.arjuna.recovery.ActionStatusService
11:19:52,007 INFO  [jbossatx] ARJUNA-32017 JBossTS Transaction Service (JTA version - tag: JBOSSTS_4_14_0_Final) - JBoss Inc.
11:19:52,103 INFO  [arjuna] ARJUNA-12202 registering bean jboss.jta:type=ObjectStore.
11:19:52,481 INFO  [AprLifecycleListener] The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/bin/native
11:19:52,764 INFO  [TomcatDeployment] deploy, ctxPath=/invoker
11:19:53,207 INFO  [ModClusterService] Initializing mod_cluster 1.1.0.Final
11:19:53,286 INFO  [RARDeployment] Required license terms exist, view vfs:/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/server/default/deploy/jboss-local-jdbc.rar/META-INF/ra.xml
11:19:53,308 INFO  [RARDeployment] Required license terms exist, view vfs:/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/server/default/deploy/jboss-xa-jdbc.rar/META-INF/ra.xml
11:19:53,322 INFO  [RARDeployment] Required license terms exist, view vfs:/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/server/default/deploy/jms-ra.rar/META-INF/ra.xml
11:19:53,347 INFO  [HornetQResourceAdapter] HornetQ resource adaptor started
11:19:53,359 INFO  [RARDeployment] Required license terms exist, view vfs:/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/server/default/deploy/mail-ra.rar/META-INF/ra.xml
11:19:53,382 INFO  [RARDeployment] Required license terms exist, view vfs:/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/server/default/deploy/quartz-ra.rar/META-INF/ra.xml
11:19:53,522 INFO  [SimpleThreadPool] Job execution threads will use class loader of thread: Thread-2
11:19:53,574 INFO  [SchedulerSignalerImpl] Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
11:19:53,575 INFO  [QuartzScheduler] Quartz Scheduler v.1.8.3 created.
11:19:53,579 INFO  [RAMJobStore] RAMJobStore initialized.
11:19:53,583 INFO  [QuartzScheduler] Scheduler meta-data: Quartz Scheduler (v1.8.3) 'JBossQuartzScheduler' with instanceId 'NON_CLUSTERED'
  Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
  NOT STARTED.
  Currently in standby mode.
  Number of jobs executed: 0
  Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
  Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.

11:19:53,583 INFO  [StdSchedulerFactory] Quartz scheduler 'JBossQuartzScheduler' initialized from an externally opened InputStream.
11:19:53,583 INFO  [StdSchedulerFactory] Quartz scheduler version: 1.8.3
11:19:53,584 INFO  [QuartzScheduler] Scheduler JBossQuartzScheduler_$_NON_CLUSTERED started.
11:19:54,133 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=DefaultDS' to JNDI name 'java:DefaultDS'
11:19:54,533 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=ConnectionFactoryBinding,name=JmsXA' to JNDI name 'java:JmsXA'
11:19:54,715 INFO  [xnio] XNIO Version 2.1.0.CR2
11:19:54,733 INFO  [nio] XNIO NIO Implementation Version 2.1.0.CR2
11:19:55,100 INFO  [remoting] JBoss Remoting version 3.1.0.Beta2
11:19:55,279 INFO  [TomcatDeployment] deploy, ctxPath=/
11:19:55,417 INFO  [HornetQServerImpl] trying to deploy queue jms.queue.ExpiryQueue
11:19:55,462 INFO  [HornetQServerImpl] trying to deploy queue jms.queue.DLQ
11:19:55,508 INFO  [service] Removing bootstrap log handlers
11:19:55,616 INFO  [org.apache.coyote.http11.Http11Protocol] Starting Coyote HTTP/1.1 on http-localhost%2F127.0.0.1-8080
11:19:55,624 INFO  [org.apache.coyote.ajp.AjpProtocol] Starting Coyote AJP/1.3 on ajp-localhost%2F127.0.0.1-8009
11:19:55,625 INFO  [org.jboss.bootstrap.impl.base.server.AbstractServer] JBossAS [6.1.0.Final "Neo"] Started in 31s:909ms
11:19:56,100 INFO  [org.jboss.web.tomcat.service.deployers.TomcatDeployment] deploy, ctxPath=/restejb

我正在使用 rest 检查我的一个项目,在注释中我在 @ApplicationPath("/rest") 和 rest 服务中的资源名称前使用斜杠 / ` @Path("/current"),所以你的 EJB 看起来一定是这样的:

@Stateless
@Path("/current")
public class ServiceImpl {

    @GET
    public Date getCurrentDate(){
        return new Date();
    }

}

你的激活器 class 类似于:

@ApplicationPath("/rest")
    public class RestApplication extends Application {
}