using Camel in a Web Application
本章主要介绍如何在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的使用