Question

I am trying to deploy a standalone application to CloudFoundry. I am using a Spring ApplicationContext in my main-method to initialize Spring and I have a simple Bean to handle the messaging with RabbitMQ.

In the spring.xml I have configured RabbitMQ and in the pom file I have added the necessary dependencies for cglib-nodep, spring-rabbit and cloudfoundry-runtime. I am further more using the maven-assembly-plugin plugin to create a single jar file which contains all the libraries, and I then deploy it to cloudfoundry with the vmc-tool.

When I deploy the jar-file to CloudFoundry I am getting the following error:

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]

Here is my 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>

And the configuration of the maven-assembly-plugin:

<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>

What could be the reason for the above error? Is there something wrong with how I configured the maven-assembly-plugin, or is there really a problem in the spring.xml?

Update

I was able to solve the error, by adding the spring-context dependency to my root pom as a managed dependency and then referencing it from my module without the version element. Now I am getting the same error but this time the Exception complains about the http://schema.cloudfoundry.org/spring schema.

Was it helpful?

Solution

[Update] I recommend to take a look at the cf-maven-plugin, which makes it much easier to deploy to CloudFoundry, so its no longer needed to work with the vmc tool directly. The GitHub page explains both howto deploy normal and standalone applications with this plugin, and also explains to use the appassembler-maven-plugin for standalone applications. This blog post is also useful to get started. [/Update]

It turned out I was deploying the application in a wrong way to CloudFoundry. I was using the maven-assembly-plugin, which unpacked the class files of all dependencies into the jar file. In fact I had to use the 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>

I then deployed the application to CloudFoundry like this from the the target/ folder

vmc push <myappname> --path=appassembler

As run command I needed to choose the name of the run script in the appassembler/bin folder. For example bin/start-up-myapp.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top