using Camel in a Web Application

上篇,介绍了如何用控制台加载camel,route。

本章主要介绍如何在web application中使用  camel。

Setp1 :   web.xml   主要添加 是添加 spring 的 contextLoaderListener,因为 camel的route通过spring  - applicationContext来加载  。

注意,下面有注释掉 context-param ,新手特别需要注意,默认会在 web-inf目录下查找 applicationContext。你的文件不在 web-inf ,可用通过 context-param 指定。

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">
 
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!--    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>applicationContext.xml</param-value>
    </context-param>-->
</web-app>

Setp2: applicationContext.xml 


下面配置中用到的bean 也是是在上一篇中有所提到

主要是配置from process to,详解参照上一篇 

<?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:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/context 
       http://www.springframework.org/schema/context/spring-context-2.5.xsd
       http://camel.apache.org/schema/spring 
       http://camel.apache.org/schema/spring/camel-spring.xsd">
    
    <bean id="myReviveProcess" class="com.smart.fulfilcamel.reviveProcess"/>
    <camelContext id="testOne" xmlns="http://camel.apache.org/schema/spring">
        <route>
            <from uri="jetty:http://localhost:8777/FulfilCamel/revive?sessionSupport=true"/>
            <removeHeaders pattern="CamelHttp*" />
            <process ref="myReviveProcess"/>
            <to uri="http://localhost:8007/FulfilCamel/fulfil"/>
        </route>
    </camelContext>
</beans>

Then boot up your web application and you're good to go!

官网参考


下次介绍  direct的使用 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值