所以我在Spring项目中设置与JMS的连接存在这个问题。问题出在我的客户端实现中,如下所示:
public class EndpointHelper implements Runnable{
@Inject
public InputDatabaseService inputProxy;
private Person mickey = new Person("Mickey", "Mouse");
public void run() {
inputProxy.input(mickey);
}
}
其中InputDataService是方法输入(Person)的接口和输入法向数据库添加人。 我有例外:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'endpointHelper': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public pl.cos.test.camel.service.InputDatabaseService pl.cos.test.ws.endpoint.EndpointHelper.inputProxy; nested exception is org.springframework.jms.MessageFormatException: [C4014]: Serialize message failed. - cause: java.io.NotSerializableException: org.springframework.web.context.support.XmlWebApplicationContext; nested exception is com.sun.messaging.jms.MessageFormatException: [C4014]: Serialize message failed. - cause: java.io.NotSerializableException: org.springframework.web.context.support.XmlWebApplicationContext
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:925)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:472)
org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
javax.servlet.GenericServlet.init(GenericServlet.java:160)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
java.lang.Thread.run(Thread.java:722)
Person.java类:
package pl.famoc.test.camel.service; import java.io.Serializable;
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
private String firstName;
private String lastName;
public Person(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
public void setFirst(String first){
this.firstName = first;
}
public void setLast(String last){
this.lastName = last;
}
public String getFirst(){
return firstName;
}
public String getLast(){
return lastName;
}
}
有谁知道我做错了什么?
答案 0 :(得分:0)
好的,我已经弄明白了。问题不是序列化,而是处理方法的Context
变量的类型,我错误地在包中创建了EndpointHelper
类,它是我的Spring上下文的基本组件:<context:component-scan base-package="pl.cos.test.ws.endpoint" />
当我想要XmlWebApplicationContext
时,导致EndpointHelper被ApplicationContext
所困扰的原因。
简单地将EndpointHelper
放到另一个包中解决了这个问题。