2011-10-25 66 views
1

我有一個獨立的Spring命令和控制應用程序,通過Spring JMS API使用ActiveMQ廣播系統狀態。這工作正常,我已經測試了它,並有一個測試客戶端程序,可以註冊聽該主題。通過Spring問題使用ActiveMQ GWT問題

我也有一個基於Spring的GWT應用程序,我嘗試將它註冊到ActiveMQ主題之一,以便它可以接收來自C應用程序的狀態消息。在GWT項目,我有WEB-INF下的applicationContext.xml一個:

<?xml version="1.0" encoding="UTF-8"?> 

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:amq="http://activemq.apache.org/schema/core" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
    http://activemq.apache.org/schema/core 
    http://activemq.apache.org/schema/core/activemq-core-5.2.0.xsd"> 

    <amq:topic id="embedded.sysModel" physicalName="org.apache.activemq.spring.embedded.sysmodel" /> 
</beans> 

當我從Eclipse中運行的GWT應用程序我碰到下面的錯誤(或多個)。

15:16:20067錯誤[org.springframework.web.context.ContextLoader] - 上下文初始化失敗 org.springframework.beans.factory.parsing.BeanDefinitionParsingException: 配置問題:找不到春天NamespaceHandler對於 XML schema命名空間[http://activemq.apache.org/schema/core] 犯規資源:ServletContext的資源 [/WEB-INF/applicationContext.xml的]

現在,在這一點上,我不甚至在GWT應用程序中有任何代碼正在引用ActiveMQ或Spring JMS模板。我起初是這麼做的,但我支持所有事情找到第一個失敗點。它似乎是amq:主題行。如果我將該行註釋到applicationContext.xml文件中,那麼我的GWT應用程序將初始化並運行得很好。

這裏是我的GWT

<?xml version="1.0" encoding="UTF-8"?> 
<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"> 
<!-- POM generated by gwt-maven-plugin archetype --> 
<modelVersion>4.0.0</modelVersion> 
<groupId>gui-spring-gwt</groupId> 
<artifactId>ourappgui</artifactId> 
<packaging>war</packaging> 
<version>2.0</version> 

<properties> 

    <!-- convenience to define GWT version in one place --> 
    <gwt.version>2.4.0</gwt.version> 
    <spring.version>3.0.6.RELEASE</spring.version> 

    <!-- tell the compiler we can use 1.5 --> 
    <maven.compiler.source>1.6</maven.compiler.source> 
    <maven.compiler.target>1.6</maven.compiler.target> 

</properties> 

<dependencies> 

    <!-- GWT dependencies (from central repo) --> 
    <dependency> 
     <groupId>com.google.gwt</groupId> 
     <artifactId>gwt-servlet</artifactId> 
     <version>${gwt.version}</version> 
     <scope>runtime</scope> 
    </dependency> 
    <dependency> 
     <groupId>com.google.gwt</groupId> 
     <artifactId>gwt-user</artifactId> 
     <version>${gwt.version}</version> 
     <scope>provided</scope> 
    </dependency> 

    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>servlet-api</artifactId> 
     <version>2.5</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-core</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-web</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context-support</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-aop</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-beans</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-test</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>log4j</groupId> 
     <artifactId>log4j</artifactId> 
     <version>1.2.14</version> 
    </dependency> 
    <!-- test --> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.7</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.derby</groupId> 
     <artifactId>derby</artifactId> 
     <version>10.5.3.0_1</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.derby</groupId> 
     <artifactId>derbyclient</artifactId> 
     <version>10.5.3.0_1</version> 
    </dependency> 
</dependencies> 

<build> 
    <outputDirectory>war/WEB-INF/classes</outputDirectory> 
    <plugins> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>gwt-maven-plugin</artifactId> 
      <version>2.3.0-1</version> 
      <dependencies> 
       <dependency> 
        <groupId>com.google.gwt</groupId> 
        <artifactId>gwt-user</artifactId> 
        <version>${gwt.version}</version> 
       </dependency> 
       <dependency> 
        <groupId>com.google.gwt</groupId> 
        <artifactId>gwt-dev</artifactId> 
        <version>${gwt.version}</version> 
       </dependency> 
      </dependencies> 
      <executions> 
       <execution> 
        <goals> 
         <goal>compile</goal> 
         <goal>generateAsync</goal> 
         <goal>test</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <runTarget>pevcogui.html</runTarget> 
      </configuration> 
     </plugin> 
     <!-- If you want to use the target/web.xml file mergewebxml produces, 
      tell the war plugin to use it. Also, exclude what you want from the final 
      artifact here. <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> 
      <configuration> <webXml>target/web.xml</webXml> <warSourceExcludes>.gwt-tmp/**</warSourceExcludes> 
      </configuration> </plugin> --> 

     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.0.2</version> 
      <configuration> 
       <source>${maven.compiler.source}</source> 
       <target>${maven.compiler.target}</target> 
      </configuration> 
     </plugin> 
     <plugin> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>2.1-beta-1</version> 
      <configuration> 
       <warSourceDirectory>war</warSourceDirectory> 
      </configuration> 
     </plugin> 

    </plugins> 
</build> 
</project> 

回答

0

看來,這個問題的根源在Eclipse插件GWT。我發現這篇文章:Spring NamespaceHandler issue when launching Maven-based GWT App from Eclipse IDE after migration to Spring 3其中討論了類似的問題。春季論壇上的這篇文章正在談論春季安全的類似問題。

我的解決方法是使用「mvn gwt:run」從命令行運行GWT應用程序。以這種方式啓動可以保持類路徑不變。我在cmd上使用maven獲得了一個成功的構建,我可以部署到Glassfish。它只在從Eclipse內啓動時發生錯誤。

4

的問題是,對於http://activemq.apache.org/schema/core的XSD無法找到的pom.xml。 activemq.xsd是activemq-core-xxx.jar的一部分,當這個jar包含在你的classpath中時會被發現。但是你沒有依賴於此。

所以添加依賴關係activemq-core如果使用xmlns:amq

<dependency> 
    <groupId>org.apache.activemq</groupId> 
    <artifactId>activemq-core</artifactId> 
    <version>5.5.0</version><!-- or whatever version you use --> 
</dependency> 
+0

確實,這是它的一部分。我這樣做,仍遇到同樣的問題,並進一步挖掘。感謝讓我朝這個方向發展。我的補充信息如下。 –