[英]Eclipse: Thrift inside Tomcat Servlet, ClassNotFoundException TException
我正在尝试制作一个可以进行Apache Thrift调用的Java servlet,但是在启动servlet时遇到了麻烦。
我有一个Thrift客户端 ,这是一个用于调用Thrift服务器的Java类
public class ThriftClient {
static TTransport transport;
static TProtocol protocol;
static MyService.Client client;
static long xtk_pointer;
public static void openSocket() throws TException {
transport = new TSocket("localhost", 9090);
transport.open();
protocol = new TBinaryProtocol(transport);
client = new MyService.Client(protocol);
}
我有一个Java Servlet ,它通过Thrift客户端打开套接字
public class MyServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
out.println("Hello World");
}
void startThrift(String [] args) {
try {
ThriftClient.openSocket();
但是,当我尝试运行此servlet(使用eclipse和tomcat服务器)时,出现类似以下错误
SEVERE: A child container failed during start
和org.apache.thrift.TException
的ClassNotFoundException
编辑:我所要做的就是将旧罐子添加到Tomcat服务器的类路径中。 请参阅下面的答案
我已经使用过节俭的客户端,而没有任何ClassNotFoundExceptions,并且servlet也可以独立工作。 但是,一旦添加ThriftClient.openSocket();
进入servlet时,它会中断,因此我感到Thrift和Tomcat在某种程度上发生了冲突。 有任何想法吗?
编辑:奇怪的是,我从来没有调用方法startThrift()
但我仍然收到错误。
在将Thrift jars包含到项目中的同时,还必须将它们添加到Tomcat库中
首先确保您的外部jar位于项目Java Build Path中。
Properties
Deployment Assembly
,单击“ Add...
Java Build Path Entries...
然后选择要包含的jar /库
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.