【问题标题】:How to Start Mule in Tomcat?如何在 Tomcat 中启动 Mule?
【发布时间】:2012-12-20 21:27:51
【问题描述】:

我是 mule 新手,正在尝试使用 mule 编排 Web 服务。 我已经编写了一个简单的 web 服务,但是当我尝试在 tomcat 中部署 mule web 项目时,我得到了这个日志语句。

21 Dec, 2012 2:44:59 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.6.0_27\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\oraclexe\app\oracle\product\10.2.0\server\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;;C:\Program Files\Dell\DW WLAN Card;.
21 Dec, 2012 2:45:00 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:PosMuleService' did not find a matching property.
21 Dec, 2012 2:45:00 AM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
21 Dec, 2012 2:45:00 AM org.apache.coyote.ajp.AjpProtocol init
INFO: Initializing Coyote AJP/1.3 on ajp-8009
21 Dec, 2012 2:45:00 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 770 ms
21 Dec, 2012 2:45:00 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
21 Dec, 2012 2:45:00 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.4
21 Dec, 2012 2:45:13 AM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
21 Dec, 2012 2:45:13 AM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
21 Dec, 2012 2:45:13 AM org.apache.coyote.ajp.AjpProtocol start
INFO: Starting Coyote AJP/1.3 on ajp-8009
21 Dec, 2012 2:45:13 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 13237 ms

这是我的 web.xml 文件

<?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_3_0.xsd"
  version="3.0"  metadata-complete="true">
  <display-name>PosMuleService</display-name>

  <context-param>
    <param-name>org.mule.config</param-name>
    <param-value>/WEB-INF/spring-servlet.xml,/WEB-INF/maf_services.xml</param-value>
  </context-param>

  <listener>
    <listener-class>org.mule.config.builders.MuleXmlBuilderContextListener</listener-class>
  </listener>

</web-app>

这是我的 spring-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>

<!-- START SNIPPET: beans -->
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
</beans>

这是我的 maf_services.xml

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:spring="http://www.springframework.org/schema/beans"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/3.4/mule-cxf.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/3.4/mule-http.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.4/mule.xsd">

  <flow name="helloService">
    <http:inbound-endpoint address="http://localhost:8080/PosMuleService/hello" exchange-pattern="request-response">
        <cxf:simple-service serviceClass="org.example.HelloWorld"/>
    </http:inbound-endpoint>
    <component class="org.example.HelloWorldImpl" /> 
  </flow>
  </mule>

这是我的 HelloWorld 实现

/**
 * 
 */
package org.example;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;

/**
 * @author 
 *
 */
@WebService(endpointInterface = "org.example.HelloWorld",
serviceName = "HelloWorld")
public class HelloWorldImpl implements HelloWorld {

    /* (non-Javadoc)
     * @see org.example.HelloWorld#sayHi(java.lang.String)
     */
    @WebMethod(operationName="sayHi")
    public @WebResult(name="sayHiResult")String sayHi(@WebParam(name="text")String text) {
        // TODO Auto-generated method stub
        return "Hi "+text;
    }

}

这是我的 pom.xml

<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">
  <modelVersion>4.0.0</modelVersion>
  <groupId>PosMuleService</groupId>
  <artifactId>PosMuleService</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>PosMuleService Maven Webapp</name>
  <url>http://maven.apache.org</url>
<dependencies>
    <dependency>
      <groupId>org.codehaus.groovy</groupId>
      <artifactId>groovy-all</artifactId>
      <version>1.8.1</version>
    </dependency>


    <dependency>
        <groupId>org.mule.modules</groupId>
        <artifactId>mule-module-builders</artifactId>
        <version>3.4-M1</version>
    </dependency>
    <dependency>
        <groupId>org.mule</groupId>
        <artifactId>mule-core</artifactId>
        <version>3.4-M1</version>
    </dependency>
    <dependency>
        <groupId>org.mule.modules</groupId>
        <artifactId>mule-module-scripting</artifactId>
        <version>3.4-M1</version>
    </dependency>
    <dependency>
        <groupId>org.mule.transports</groupId>
        <artifactId>mule-transport-vm</artifactId>
        <version>3.4-M1</version>
    </dependency>
    <dependency>
        <groupId>org.mule.transports</groupId>
        <artifactId>mule-transport-servlet</artifactId>
        <version>3.4-M1</version>
    </dependency>
    <dependency>
        <groupId>org.mule.transports</groupId>
        <artifactId>mule-transport-stdio</artifactId>
        <version>3.4-M1</version>
    </dependency>
    <dependency>
        <groupId>asm</groupId>
        <artifactId>asm-commons</artifactId>
        <version>3.3.1</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.14</version>
    </dependency>
</dependencies>

  <repositories>
    <repository>
      <id>mule-deps</id>
      <name>Mule Dependencies</name>
      <url>http://dist.codehaus.org/mule/dependencies/maven2</url>
    </repository>
  </repositories>
  <build>
    <finalName>PosMuleService</finalName>
  </build>
</project>

我正在使用 tomcat7.0 和 eclipse juno.. 知道为什么我的骡子无法正常启动..我既看不到服务也看不到 wsdl .. 为 URL 获取 404

http://localhost:8080/PosMuleService/hello

在服务器日志中注意我得到了这一行:INFO: No Spring WebApplicationInitializer types detected on classpath 但我在 WEB-INF 中添加了 spring-servlet.xml 文件,也尝试使用上下文加载器但没有运气。

【问题讨论】:

  • 既然你已经放弃了使用Tomcat的想法,也不会进一步探讨这个问题,也不会我提出的答案,我建议你删除这个问题。它对未来的读者没有任何价值,因为我们无法达到令人满意的解决方案。
  • 我不确定..这个问题可能对某人有帮助..

标签: java web-services soap mule spring-3


【解决方案1】:

几个问题:

  • 不要使用 Mule 加载 Spring 配置文件:从 param-value 中删除 /WEB-INF/spring-servlet.xml
  • 在 Web 容器中运行时不要使用 HTTP 入站端点:Mule 将尝试在此端口上启动 Web 服务器。而是使用 servlet 入站端点,以便 Mule 通过 Web 容器处理的 servlet 进行侦听。

在你的情况下使用:

<servlet:inbound-endpoint path="hello" />
  • 将 Mule servlet 添加到您的 web.xml。

像这样:

<servlet>
    <servlet-name>muleServlet</servlet-name>
    <servlet-class>org.mule.transport.servlet.MuleReceiverServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>muleServlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

【讨论】:

  • @我进行了这些更改,但服务器日志再次相同..我认为 mule 没有正常启动..任何想法..可能是什么原因..除了信息之外,我没有任何例外:在类路径上未检测到 Spring WebApplicationInitializer 类型
  • 请用每个文件的当前版本更新您的问题,包括启动日志。
  • 所以?你让它工作吗?如果没有,请使用每个文件的当前版本更新您的问题,包括启动日志。
【解决方案2】:

是的,我做到了,但采用了不同的方法。我无法使用tomcat做到这一点。可能我们不应该在 tomcat 上运行 mule,因为我们必须依赖 servlet 线程进行处理,我认为这会降低性能。如果我错了,请纠正我。我在某处读过这个.. 我已经安装了 mule studio 并创建了一个 mule 项目 将maf_Services.xml 和 webservices 代码添加到 mule studio 项目,并将项目作为 mule 应用程序执行。 在生产环境中,我将使用 mule studio 导出我的 mule 项目,并使用 mule 独立服务器部署我的应用程序。

【讨论】:

  • 我认为说使用 Tomcat 的 servlet 层会降低性能是不正确的。我从来没有听说过这样的说法,也没有看到任何数据。如果你可以运行独立版本——这对 Mule 来说是最自然的——你为什么要首先在 Tomcat 上运行?
  • 是的,我在某处读到了会降低性能的地方……没有获得链接,否则我会发布……无论如何,目前正在以独立方式使用骡子……
【解决方案3】:

我可以确认您要在 tomcat 上部署的应用程序有效。

在 David 建议的更改旁边,我将流定义更改如下:

<flow name="helloService">
    <servlet:inbound-endpoint path="hello" />
    <component class="org.example.HelloWorldImpl" />
</flow>

在这里你不需要任何 Spring。 如果您想使用 Spring,请在您的 mule 配置中定义以下组件:

<spring:beans>
    <spring:import resource="classpath:applicationContext.xml"/>
</spring:beans>

确保您的 Spring applicationContext 在您的类路径中。 (例如,在 maven 文件结构中,将您的 applicationContext 放在 src/main/resources/ 中)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-13
    • 2016-01-01
    • 2015-03-08
    • 2013-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-21
    相关资源
    最近更新 更多