cxf spring集合中开发Web Service遇见的java.util.Date无缺省函数问题

cxf spring集合中开发Web Service遇见的java.util.Date无缺省函数问题 

在domain中有User类

public class User {

 

         private String userName;

private String userPassword;

private String mobile;

private String email;

private String nickname;

private String region;

private java.sql.Date birthday ;

private String telephone;

private String address;

private String postcode;

private String signature;

private String imageUrl;

private int userID;

} 其中birthday类型为java.sql.Date,没有开发web service时,使用spring 和hibernate都OK 加入cxf后报错了 

 

 

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'UserWebService1111': Invocation of init method failed; nested exception is javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)

at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:282)

at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:204)

at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)

at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)

at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)

at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)

at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)

at java.util.concurrent.FutureTask.run(FutureTask.java:138)

at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

at java.lang.Thread.run(Thread.java:662)

Caused by: javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException

at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:350)

at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:239)

at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:509)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1544)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1485)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)

... 20 more

Caused by: org.apache.cxf.service.factory.ServiceConstructionException

at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:292)

at org.apache.cxf.service.factory.AbstractServiceFactoryBean.initializeDataBindings(AbstractServiceFactoryBean.java:86)

at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:444)

at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass(JaxWsServiceFactoryBean.java:682)

at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:507)

at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:241)

at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:202)

at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:101)

at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:157)

at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:202)

at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:433)

at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:322)

... 29 more

Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions

java.sql.Date does not have a no-arg default constructor.

this problem is related to the following location:

at java.sql.Date

at public java.sql.Date com.tianxiao.whut.domain.User.getBirthday()

at com.tianxiao.whut.domain.User

at private java.util.List com.tianxiao.whut.webservice.jaxws_asm.QueryByNicknameResponse._return

at com.tianxiao.whut.webservice.jaxws_asm.QueryByNicknameResponse

 

at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:106)

at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:466)

at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:298)

at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:141)

at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1157)

at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:145)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:202)

at javax.xml.bind.ContextFinder.find(ContextFinder.java:363)

at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)

at org.apache.cxf.jaxb.JAXBContextCache.createContext(JAXBContextCache.java:260)

at org.apache.cxf.jaxb.JAXBContextCache.getCachedContextAndSchemas(JAXBContextCache.java:169)

at org.apache.cxf.jaxb.JAXBDataBinding.createJAXBContextAndSchemas(JAXBDataBinding.java:418)

at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:290)

... 40 more

 

请问这个该如何解决?

 

4个回答

[quote]java.sql.Date does not have a no-arg default constructor.[/quote]
也就是说java.sql.Date这个类是不能这样创建实例的
[code="java"]java.sql.Date date = new java.sql.Date();[/code]

要用
[code="java"]java.sql.Date date = new java.sql.Date(new java.util.Date().getTime() );[/code]

Web Service 在进行接口封装过程中,遇到调用实体类的情况,接口会自动去识别实体类数据的基本类型。例如 int、String等。在此,我们需要注意的是,有些数据类型是不能被web service 所识别的。其中常见的日期类型,如果我们的基本类型采用java.sql.Date的话是会报错的(报错信息类似于如下所示)。

而应当用java.util.Date类。

其实是可以支持java.sql.Date的,这和java.util.Date区别并不大,能使用java对象,所有的java对象都应该可以使用。
你的问题应该出在你调用 QueryByNickname接口返回List时,其中构造对象时使用了无参数的java.sql.Date类型,你检查一下代码。

好像只能用java.util.Date sql 不能序列

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!