我使用 apache mina 为我的示例程序关注了这个链接。
这些是我与代码一起使用的 lib 文件。
- mina-core-2.0.7.jar
- slf4j-api-1.7.5.jar
- slf4j-jdk14-1.7.5.jar
我收到以下错误:
Exception in thread "main" java.lang.ClassCastException: org.slf4j.impl.JDK14LoggerAdapter cannot be cast to java.util.logging.Logger
at minafiletrans.MinaServerHandler.<init>(MinaServerHandler.java:12)
at minafiletrans.Minafiletrans.main(Minafiletrans.java:23)
Java Result: 1
这是我的代码:
package minafiletrans;
import java.util.logging.Logger;
import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;
import org.slf4j.LoggerFactory;
public class MinaServerHandler extends IoHandlerAdapter
{
@SuppressWarnings("NonConstantLogger")
private final Logger logger = (Logger) LoggerFactory.getLogger(getClass());
@Override
public void sessionOpened(IoSession session)
{
// set idle time to 10 seconds
session.getConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
session.setAttribute("Values: ");
}
@Override
@SuppressWarnings("LoggerStringConcat")
public void messageReceived(IoSession session, Object message)
{
logger.info("Message received in the server..");
logger.info("Message is: " + message.toString());
}
@Override
public void sessionIdle(IoSession session, IdleStatus status)
{
logger.info("Disconnecting the idle.");
// disconnect an idle client
session.close(true);
}
@Override
public void exceptionCaught(IoSession session, Throwable cause)
{
// close the connection on exceptional situation
session.close(true);
}
}
我已经添加了所有必需的 lib 文件。那么为什么我会出现这个错误。解决此错误的任何建议。