我的 Hibernate 处于集群模式,它使用 ActiveMQ 在节点之间发送消息。第一次当我尝试查看 AddLuceneWork 消息正文时,显示了错误,但我在 ACTIVE_MQ/lib 中添加了缺少类的 JAR。之后显示另一个错误:
Cannot display ObjectMessage body. Reason: Failed to build body from content.
Serializable class not available to broker. Reason: java.lang.ClassNotFoundException:
Forbidden class org.hibernate.search.backend.AddLuceneWork!
This class is not trusted to be serialized as ObjectMessage payload.
Please take a look at http://activemq.apache.org/objectmessage.html for more information on how to configure trusted classes.
因此,根据文档,我将此行添加到 ACTIVE_MQ/bin/env 文件中:
ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS -Dorg.apache.activemq.SERIALIZABLE_PACKAGES=*"
这导致我在控制台中出现异常:
org.apache.jasper.JasperException: An exception occurred processing JSP page /message.jsp at line 186
183: </thead>
184: <tbody>
185: <tr>
186: <td><div class="message"><pre class="prettyprint"><c:out value="${requestContext.messageQuery.body}"/></pre></div></td>
187: </tr>
188: </tbody>
189: </table>
这是整个堆栈跟踪:
at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)[apache-jsp-8.0.9.M3.jar:2.3]
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)[apache-jsp-8.0.9.M3.jar:2.3]
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:405)[apache-jsp-8.0.9.M3.jar:2.3]
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:349)[apache-jsp-8.0.9.M3.jar:2.3]
at org.eclipse.jetty.jsp.JettyJspServlet.service(JettyJspServlet.java:107)[apache-jsp-9.2.13.v20150730.jar:9.2.13.v20150730]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)[tomcat-servlet-api-8.0.24.jar:]
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:808)[jetty-all-9.2.13.v20150730.jar:9.2.13.v20150730]
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669)[jetty-all-9.2.13.v20150730.jar:9.2.13.v20150730]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)[spring-web-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)[spring-web-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)[jetty-all-9.2.13.v20150730.jar:9.2.13.v20150730]
at org.apache.activemq.web.SessionFilter.doFilter(SessionFilter.java:45)[activemq-web-5.13.4.jar:5.13.4]
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)[jetty-all-9.2.13.v20150730.jar:9.2.13.v20150730]
at org.apache.activemq.web.filter.ApplicationContextFilter.doFilter(ApplicationContextFilter.java:102)[file:/home/openkm/activemq-5.13.4/webapps/admin/WEB-INF/classes/:]
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)[jetty-all-9.2.13.v20150730.jar:9.2.13.v20150730]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)[jetty-all-9.2.13.v20150730.jar:9.2.13.v20150730]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)[jetty-all-9.2.13.v20150730.jar:9.2.13.v20150730]
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:542)[jetty-all-9.2.13.v20150730.jar:9.2.13.v20150730]
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)[jetty-all-9.2.13.v20150730.jar:9.2.13.v20150730]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)[jetty-all-9.2.13.v20150730.jar:9.2.13.v20150730]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)[jetty-all-9.2.13.v20150730.jar:9.2.13.v20150730]
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)[jetty-all-9.2.13.v20150730.jar:9.2.13.v20150730]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)[jetty-all-9.2.13.v20150730.jar:9.2.13.v20150730]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)[jetty-all-9.2.13.v20150730.jar:9.2.13.v20150730]
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110)[jetty-all-9.2.13.v20150730.jar:9.2.13.v20150730]
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:542)[jetty-all-9.2.13.v20150730.jar:9.2.13.v20150730]
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110)[jetty-all-9.2.13.v20150730.jar:9.2.13.v20150730]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)[jetty-all-9.2.13.v20150730.jar:9.2.13.v20150730]
at org.eclipse.jetty.server.Server.handle(Server.java:499)[jetty-all-9.2.13.v20150730.jar:9.2.13.v20150730]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)[jetty-all-9.2.13.v20150730.jar:9.2.13.v20150730]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)[jetty-all-9.2.13.v20150730.jar:9.2.13.v20150730]
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)[jetty-all-9.2.13.v20150730.jar:9.2.13.v20150730]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)[jetty-all-9.2.13.v20150730.jar:9.2.13.v20150730]
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)[jetty-all-9.2.13.v20150730.jar:9.2.13.v20150730]
at java.lang.Thread.run(Thread.java:745)[:1.8.0_121]
可以显示我想要的信息吗?
提前致谢。
当您的 java 类具有 activemq 的类路径中仍然缺少的依赖项或未实现 Serialized 接口(interface)时,就会发生这种情况。要解决此问题,请尝试将所有依赖项添加到 activemq 类路径。
编辑:在我的机器中复制了相同的错误,上述解决方案对我有用。
创建了两个 Java 类
import java.io.Serializable;
public class MyBean1 implements Serializable{
public String f1;
public String f2;
}
和
import java.io.Serializable;
import org.apache.logging.log4j.Logger;
public class MyBean2 implements Serializable {
public String f1;
public Logger f2;
}
并构建了一个 jar (其中没有 Logger 类)。然后在activemq中配置jar,如前所述here .
最后创建两个类的java对象并将其发送到队列。
public class ActiveMqConnection {
private static String url = "tcp://localhost:61616";
private static String subject = "TEST_QUEUE";
public static void main(String args[]) throws Exception{
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
Connection connection = connectionFactory.createConnection();
connection.start();
Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue(subject);
// MessageProducer is used for sending beans to the queue.
MessageProducer producer = session.createProducer(destination);
MyBean1 bean1 = new MyBean1();
bean1.f1 = "Tom";
bean1.f2 = "John";
Message message1 = session.createObjectMessage(bean1);
producer.send(message1);//This bean message1 you will be able to see it in ActiveMq
MyBean2 bean2 = new MyBean2();
bean2.f1 = "Jerry";
// bean2.f2 = 1;
bean2.f2 = LogManager.getLogger();
Message message2 = session.createObjectMessage(bean2);
producer.send(message2);//This will throw Error when you try to view it in ActiveMq
System.out.println("done");
connection.close();
}
}
请注意,在 activemq 中配置的 jar 文件中不存在 Logger 类。要解决它,请尝试将 log4j-api 添加到 activemq 类路径,它将解决该错误
我是一名优秀的程序员,十分优秀!