我正在尝试将独立应用程序部署到 CloudFoundry。我ApplicationContext
在我的方法中使用 Springmain
来初始化 Spring,并且我有一个简单的 Bean 来处理与 RabbitMQ 的消息传递。
在spring.xml
我配置了 RabbitMQ 和 pom 文件中,我添加了必要的依赖项cglib-nodep
,spring-rabbit
和cloudfoundry-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-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>
上述错误的原因可能是什么?我配置 maven-assembly-plugin 的方式有问题,还是 spring.xml 中真的有问题?
更新
我能够通过将 spring-context 依赖项作为托管依赖项添加到我的根 pom 中,然后在没有版本元素的情况下从我的模块中引用它来解决该错误。现在我遇到了同样的错误,但这次异常抱怨http://schema.cloudfoundry.org/spring模式。