【问题标题】:GWT using ActiveMQ through Spring problemsGWT 通过 Spring 问题使用 ActiveMQ
【发布时间】:2011-10-25 19:26:43
【问题描述】:

我有一个独立的 Spring 命令和控制应用程序,它使用 ActiveMQ 通过 Spring JMS API 广播系统状态。这很好用,我已经对其进行了测试,并且有一个可以注册收听主题的测试客户端程序。

我还有一个基于 Spring 的 GWT 应用程序,我正在尝试让它注册到 ActiveMQ 主题之一,以便它可以接收来自 C&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:20,067 错误 [org.springframework.web.context.ContextLoader] - 上下文初始化失败 org.springframework.beans.factory.parsing.BeanDefinitionParsingException: 配置问题:找不到 Spring NamespaceHandler for XML 模式命名空间 [http://activemq.apache.org/schema/core] 违规资源:ServletContext 资源 [/WEB-INF/applicationContext.xml]

现在,我什至在 GWT 应用程序中没有任何引用 ActiveMQ 或 Spring JMS 模板的代码。起初我是这样做的,但我放弃了一切以找到第一个失败点。它似乎是 amq:topic 行。如果我从 applicationContext.xml 文件中注释掉该行,我的 GWT 应用程序就会初始化并运行良好。

这是我的 GWT 的 pom.xml

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

【问题讨论】:

    标签: spring gwt maven jms activemq


    【解决方案1】:

    问题是找不到http://activemq.apache.org/schema/core 的xsd。 activemq.xsd 是 activemq-core-xxx.jar 的一部分,当这个 jar 在你的类路径中时会被找到。但你不依赖它。

    所以如果你使用xmlns:amq,则将依赖添加到activemq-core

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

    【讨论】:

    • 确实,这是其中的一部分。我这样做了,仍然遇到同样的问题,并进一步挖掘。谢谢你让我朝那个方向发展。我的修复附加信息如下。
    【解决方案2】:

    看来这个问题的根源在于 Eclipse GWT 插件。我发现这篇文章:Spring NamespaceHandler issue when launching Maven-based GWT App from Eclipse IDE after migration to Spring 3 讨论了类似的问题。 Spring 论坛上的这篇文章讨论了 spring-security 的类似问题。

    我的解决方法是使用“mvn gwt:run”从命令行运行 GWT 应用程序。以这种方式启动可以保持类路径完好无损。我在 cmd 行使用 maven 成功构建,并且可以部署到 Glassfish。只有从 Eclipse 中启动时才会出现错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-01
      • 2010-10-01
      • 1970-01-01
      • 2015-01-22
      • 1970-01-01
      • 2011-02-22
      相关资源
      最近更新 更多