春季启动ActiveMQ JMS显示资源不存在:ServletContext资源[/xsd/product.xsd]

时间:2018-11-11 07:21:31

标签: java spring spring-boot jms activemq

以下是我的JMSConfig.java

@Configuration
public class JMSConfig {

    private static final Logger logger = LoggerFactory.getLogger(JMSConfig.class);

    @Bean
    public MarshallingMessageConverter createMarshallingMessageConverter(final Jaxb2Marshaller jaxb2Marshaller) {
        return new MarshallingMessageConverter(jaxb2Marshaller);
    }

    @Bean
    public Jaxb2Marshaller createJaxb2Marshaller(@Value("${context.path}") final String contextPath,
                                             @Value("${schema.location}") final Resource schemaResource) {

        Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
        jaxb2Marshaller.setContextPath(contextPath);
        try {
        jaxb2Marshaller.setSchema(schemaResource);
        }catch(Exception e) {
            logger.error("Error occurred while getting xsd resource for jaxbsMarshaller. Reason :"+e);
        }

        Map<String, Object> properties = new HashMap<>();
        properties.put(Marshaller.JAXB_FORMATTED_OUTPUT, true);

        jaxb2Marshaller.setMarshallerProperties(properties);
        return jaxb2Marshaller;
    }

}

以下是我的使用者模式文件:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.admin.com/product"
    xmlns:tns="http://www.example.org/product"
    elementFormDefault="qualified">

    <element name="product">
        <complexType>
            <sequence>
                <element name="productName" type="string"></element>
            </sequence>
            <attribute name="productId" type="string" use="required"></attribute>
        </complexType>
    </element>
</schema>

以下是我的application.properties

# ===============================
# = ACTIVEMQ & JMS 
# ===============================
spring.activemq.broker-url=tcp://localhost:61616
outbound.endpoint=ORDER.PROCESSING.D
context.path=com.admin.product
schema.location=xsd/product.xsd

以下是我的pom.xml:

<dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-jms</artifactId>
            <version>5.1.0.RELEASE</version>
        </dependency>
        <!-- These two dependency is for JMS messeging -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-activemq</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-broker</artifactId>
        </dependency>

        <dependency>
            <groupId>com.admin</groupId>
            <artifactId>admin1.5.7</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-oxm</artifactId>
        </dependency>

关于如何消除此错误的任何建议?

当我运行发布者spring boot应用程序时,我看到找不到资源错误,这是因为uts无法找到模式文件product.xsd。

我还在发布者pom.xml中添加了消费者依赖性:

<dependency>
            <groupId>com.admin</groupId>
            <artifactId>admin1.5.7</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

0 个答案:

没有答案