2014-10-04 80 views
1

我開始創建一個新的Java Web應用程序可擴展,但不工作,因爲我得到錯誤 「503服務不可用沒有服務器可用來處理此請求。 使用im RESTful服務可伸縮的Java Web應用程序openshift - 503錯誤HAProxy

我的代碼是:

識別TestClass

@Path( 「/測試」)

public class TestClass { 

    @GET 
    public String getName() { 
     return "John"; 
    } 
} 

的web.xml

<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
    metadata-complete="false"> 

    <!-- Auto scan REST service --> 
    <context-param> 
     <param-name>resteasy.scan</param-name> 
     <param-value>true</param-value> 
    </context-param> 

    <listener> 
     <listener-class> 
      org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap 
     </listener-class> 
    </listener> 

    <servlet> 
     <servlet-name>resteasy-servlet</servlet-name> 
     <servlet-class> 
      org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher 
     </servlet-class> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>resteasy-servlet</servlet-name> 
     <url-pattern>/*</url-pattern> 
    </servlet-mapping> 
</web-app> 

POM

<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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>myApp</groupId> 
    <artifactId>myApp</artifactId> 
    <packaging>war</packaging> 
    <version>1.0</version> 
    <name>myApp</name> 
    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <maven.compiler.source>1.6</maven.compiler.source> 
     <maven.compiler.target>1.6</maven.compiler.target> 
    </properties> 
    <dependencies> 
     <dependency> 
      <groupId>org.jboss.spec</groupId> 
      <artifactId>jboss-javaee-6.0</artifactId> 
      <version>1.0.0.Final</version> 
      <type>pom</type> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.jboss.resteasy</groupId> 
      <artifactId>resteasy-jaxrs</artifactId> 
      <version>2.3.1.GA</version> 
      <scope>provided</scope> 
     </dependency> 

     <dependency> 
      <groupId>org.jboss.resteasy</groupId> 
      <artifactId>resteasy-jackson-provider</artifactId> 
      <version>2.3.1.GA</version> 
      <scope>provided</scope> 
     </dependency> 
    </dependencies> 
    <profiles> 
     <profile> 
      <!-- When built in OpenShift the 'openshift' profile will be used when 
       invoking mvn. --> 
      <!-- Use this profile for any OpenShift specific customization your app 
       will need. --> 
      <!-- By default that is to put the resulting archive into the 'deployments' 
       folder. --> 
      <!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html --> 
      <id>openshift</id> 
      <build> 
       <finalName>myApp</finalName> 
       <plugins> 
        <plugin> 
         <artifactId>maven-war-plugin</artifactId> 
         <version>2.1.1</version> 
         <configuration> 
          <outputDirectory>deployments</outputDirectory> 
          <warName>myApp</warName> 
         </configuration> 
        </plugin> 
       </plugins> 
      </build> 
     </profile> 
    </profiles> 
</project> 

在我Haproxy.cfg,我有這個行選項httpchk GET /對myApp 任何人都可以幫助嗎?

回答

0

如果您的應用程序沒有監聽根上下文(/),那麼haproxy會將您的應用程序視爲關閉。您需要在根上下文上監聽某些內容,或將監視選項更改爲指向輪詢時返回200(成功)的url。

您是否將httpchk GET /更改爲httpchk GET/myApp?

即使您將應用程序更改爲部署在/ myApp,仍需要在該URL上獲得200的成功。

+0

所以也許如果我將httpchk GET/myApp更改爲httpchk GET/myApp/test,應該可以正常工作? – user1851366 2014-10-04 17:35:16

+0

如果你在/ myApp/test上有響應,那麼是的。它甚至可以像添加check.html文件一樣簡單,它會檢查以確保您的應用程序已啓動。 – 2014-10-04 19:56:52

+0

好吧,就像你在我的課程「TestClass」中看到的那樣,我返回了一個字符串。應該是一個文件?不能是一個字符串或對象? – user1851366 2014-10-08 22:51:44

相關問題