继上一篇“Camel中配置不同servlet的一种方法”之后,经过项目实践又发现了一种更简单的配置不同servlet请求的方法,具体如下:

在web.xml中配置

<!-- Camel servlet -->
  <servlet>
    <servlet-name>CamelServlet</servlet-name>
    	<servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <!-- Camel servlet mapping -->
  <servlet-mapping>
    <servlet-name>CamelServlet</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>

在camel.xml中配置

<camel:route id="servlet1">
<camel:from uri="servlet:///hello"/>
</camel:route>

<camel:route id="servlet2">
<camel:from uri="servlet:///hello2"/>
</camel:route>


其中myWeb是你的项目名称,在请求http://localhost:8080/myWeb/hello的时候就会调用进入routeId为servlet1的处理逻辑;请求http://localhost:8080/myWeb/hello2的时候就会调用进入routeId为servlet2的处理逻辑.

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐