2013-04-23 83 views
1

我正在嘗試將獨立應用程序部署到CloudFoundry。我在我的main-method中使用Spring ApplicationContext來初始化Spring,我有一個簡單的Bean來處理RabbitMQ的消息傳遞。Cloudfoundry:使用Spring和RabbitMQ部署獨立應用程序

spring.xml我已經配置的RabbitMQ和在POM文件我已經添加了必要的依賴關係cglib-nodepspring-rabbitcloudfoundry-runtime。我進一步使用maven-assembly-plugin插件創建了一個包含所有庫的單個jar文件,然後使用vmc-tool將它部署到cloudfoundry。

當我部署jar -file到CloudFoundry我收到以下錯誤:

Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: 
Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace 
[http://www.springframework.org/schema/context] 

Offending resource: class path resource [spring.xml] 

[stacktrace ommited] 

這裏是我的spring.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:rabbit="http://www.springframework.org/schema/rabbit" 
    xmlns:cloud="http://schema.cloudfoundry.org/spring" 
    xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-3.0.xsd 
     http://www.springframework.org/schema/rabbit 
     http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd 
     http://schema.cloudfoundry.org/spring 
     http://schema.cloudfoundry.org/spring/cloudfoundry-spring-0.7.xsd"> 

    <context:component-scan base-package="mypackage" /> 

    <!-- Obtain a connection to the RabbitMQ via cloudfoundry-runtime: --> 
    <cloud:rabbit-connection-factory id="connectionFactory"/> 

    <!-- Set up the AmqpTemplate/RabbitTemplate: --> 
    <rabbit:template connection-factory="connectionFactory"/> 

    <!-- Request that queues, exchanges and bindings be automatically 
     declared on the broker: --> 
    <rabbit:admin connection-factory="connectionFactory"/> 

    <!-- Declare the "messages" queue: --> 
    <rabbit:queue name="messages" durable="true"/> 
</beans> 

而且Maven的組裝插件的配置:

<plugin> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <configuration> 
     <archive> 
      <manifest> 
       <mainClass>at.ac.tuwien.infosys.dse2013s.group17.allocator.ui.StartUpAllocator</mainClass> 
      </manifest> 
     </archive> 
     <descriptorRefs> 
      <descriptorRef>jar-with-dependencies</descriptorRef> 
     </descriptorRefs> 
    </configuration> 
    <executions> 
     <execution> 
      <id>make-assembly</id> <!-- this is used for inheritance merges --> 
      <phase>package</phase> <!-- bind to the packaging phase --> 
      <goals> 
      <goal>single</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 

可能是什麼原因以上錯誤?如何配置maven-assembly-plugin,或者在spring.xml中確實存在問題嗎?

更新

我能夠解決的錯誤,通過將彈簧方面依賴於我的根POM作爲託管依賴,然後從我的模塊引用它,而不version元素。現在我得到了同樣的錯誤,但是這次異常抱怨http://schema.cloudfoundry.org/spring模式。

回答

1

[更新]我建議查看cf-maven-plugin,這使得部署到CloudFoundry變得更容易,因此不再需要直接使用vmc工具。 GitHub頁面解釋瞭如何在此插件中部署正常獨立應用程序,並解釋如何在獨立應用程序中使用appassembler-maven插件。這blog post也是開始使用。

原來我是以錯誤的方式將應用程序部署到CloudFoundry。我使用的是maven-assembly-plugin,它將所有依賴項的類文件解壓縮到jar文件中。事實上,我不得不使用appassembler-maven-plugin

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>appassembler-maven-plugin</artifactId> 
    <version>1.1.1</version> 
    <executions> 
     <execution> 
      <phase>package</phase> 
      <goals> 
       <goal>assemble</goal> 
      </goals> 
      <configuration> 
       <assembledirectory>target</assembledirectory> 
       <programs> 
        <program> 
         <mainClass>my.package.myclass</mainClass> 
        </program> 
       </programs> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

我然後將應用程序部署到CloudFoundry這樣從該target/文件夾

vmc push <myappname> --path=appassembler 

由於運行命令,我需要選擇運行腳本的名稱在appassembler/bin文件夾中。例如bin/start-up-myapp

相關問題