背景环境说明
工作中难免遇到历史项目,今天算是见识了。项目为spring4+strust2+hibernate+cxf的工程,主要功能是给外部封装本地jira的一些接口调用,坑爹的是jira系统版本为7.10.2#710003(目前最新为8.x.x,还不算太旧),但jira-rest-java-client却是2012年的1.1版本(最新的都5了,相当无语),其实这些还可以接受。最受不了的是工程结构应该是gradle(v2.0.0)发布没多久时的那种结构,本人相当的懒(涉及开发环境的倒退不想玩了),至今本地也没跑起来。
1.千辛万苦导入工程代码
凭借以往经验,gradle项目的git库里应该是没有如下闲杂代码的
一开始git clone后没注意,直接import,报各种环境相关的错误。
一顿删除操作后,重新导入,出现如下错误(未保留实际现场)
Could not find method leftShift() for arguments
起初也没在意,抱着项目能运行的理解,以为问题出在导入工程上,来来回回重新git clone多次,才去google了一把这个错,
原来是gradle 4以后<<操作符已经废弃,5就直接干掉了。
| 参考 https://blog.csdn.net/djzhao627/article/details/90292063
此处省略无数 << 转 doLast 操作
2.本地开发直接上sit
幸好在jenkins上存在打包脚本,本地环境就不搭了(偷个懒,哈哈)
然jenkins打包出了个错,心慌慌啊
08-28 14:57:12.391 [main] WARN org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:487) - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'commJiraService': 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:1566) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) ~[spring-context-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) ~[spring-context-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) [spring-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) [spring-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) [spring-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:800) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:444) [jetty-servlet-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:791) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:294) [jetty-servlet-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1349) [jetty-webapp-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1342) [jetty-webapp-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:741) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:505) [jetty-webapp-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [jetty-util-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:41) [jetty-deploy-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:186) [jetty-deploy-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:498) [jetty-deploy-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:146) [jetty-deploy-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:180) [jetty-deploy-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.deploy.providers.WebAppProvider.fileAdded(WebAppProvider.java:461) [jetty-deploy-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:64) [jetty-deploy-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:609) [jetty-util-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:528) [jetty-util-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.util.Scanner.scan(Scanner.java:391) [jetty-util-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:313) [jetty-util-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [jetty-util-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:150) [jetty-deploy-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [jetty-util-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:560) [jetty-deploy-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:235) [jetty-deploy-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [jetty-util-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132) [jetty-util-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.server.Server.start(Server.java:387) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114) [jetty-util-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.server.Server.doStart(Server.java:354) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [jetty-util-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1255) [jetty-xml-9.2.10.v20150310.jar:9.2.10.v20150310]
at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_40]
at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1174) [jetty-xml-9.2.10.v20150310.jar:9.2.10.v20150310]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_40]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_40]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_40]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_40]
at org.eclipse.jetty.start.Main.invokeMain(Main.java:321) [start.jar:9.2.10.v20150310]
at org.eclipse.jetty.start.Main.start(Main.java:817) [start.jar:9.2.10.v20150310]
at org.eclipse.jetty.start.Main.main(Main.java:112) [start.jar:9.2.10.v20150310]
Caused by: javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException
at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:371) ~[cxf-rt-frontend-jaxws-3.0.3.jar:3.0.3]
at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:251) ~[cxf-rt-frontend-jaxws-3.0.3.jar:3.0.3]
at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:539) ~[cxf-rt-frontend-jaxws-3.0.3.jar:3.0.3]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_40]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_40]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_40]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_40]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1694) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1562) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
... 54 common frames omitted
Caused by: org.apache.cxf.service.factory.ServiceConstructionException: null
at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:327) ~[cxf-rt-databinding-jaxb-3.0.3.jar:3.0.3]
at org.apache.cxf.service.factory.AbstractServiceFactoryBean.initializeDataBindings(AbstractServiceFactoryBean.java:86) ~[cxf-core-3.0.3.jar:3.0.3]
at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:467) ~[cxf-rt-wsdl-3.0.3.jar:3.0.3]
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass(JaxWsServiceFactoryBean.java:704) ~[cxf-rt-frontend-jaxws-3.0.3.jar:3.0.3]
at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:527) ~[cxf-rt-wsdl-3.0.3.jar:3.0.3]
at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:261) ~[cxf-rt-wsdl-3.0.3.jar:3.0.3]
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:215) ~[cxf-rt-frontend-jaxws-3.0.3.jar:3.0.3]
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:102) ~[cxf-rt-frontend-simple-3.0.3.jar:3.0.3]
at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:159) ~[cxf-rt-frontend-simple-3.0.3.jar:3.0.3]
at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:211) ~[cxf-rt-frontend-jaxws-3.0.3.jar:3.0.3]
at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:456) ~[cxf-rt-frontend-jaxws-3.0.3.jar:3.0.3]
at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:334) ~[cxf-rt-frontend-jaxws-3.0.3.jar:3.0.3]
... 63 common frames omitted
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:106) ~[jaxb-impl-2.2.7.jar:2.2.7]
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:471) ~[jaxb-impl-2.2.7.jar:2.2.7]
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:303) ~[jaxb-impl-2.2.7.jar:2.2.7]
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:142) ~[jaxb-impl-2.2.7.jar:2.2.7]
at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1174) ~[jaxb-impl-2.2.7.jar:2.2.7]
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:162) ~[jaxb-impl-2.2.7.jar:2.2.7]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_40]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_40]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_40]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_40]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:247) ~[na:1.8.0_40]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:234) ~[na:1.8.0_40]
at javax.xml.bind.ContextFinder.find(ContextFinder.java:441) ~[na:1.8.0_40]
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:641) ~[na:1.8.0_40]
at org.apache.cxf.common.jaxb.JAXBContextCache$2.run(JAXBContextCache.java:347) ~[cxf-core-3.0.3.jar:3.0.3]
at org.apache.cxf.common.jaxb.JAXBContextCache$2.run(JAXBContextCache.java:345) ~[cxf-core-3.0.3.jar:3.0.3]
at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_40]
at org.apache.cxf.common.jaxb.JAXBContextCache.createContext(JAXBContextCache.java:345) ~[cxf-core-3.0.3.jar:3.0.3]
at org.apache.cxf.common.jaxb.JAXBContextCache.getCachedContextAndSchemas(JAXBContextCache.java:246) ~[cxf-core-3.0.3.jar:3.0.3]
at org.apache.cxf.jaxb.JAXBDataBinding.createJAXBContextAndSchemas(JAXBDataBinding.java:470) ~[cxf-rt-databinding-jaxb-3.0.3.jar:3.0.3]
at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:325) ~[cxf-rt-databinding-jaxb-3.0.3.jar:3.0.3]
... 74 common frames omitted
这下懵逼了,检查了一下cxf的版本为3.0.0,最新的3.3.2,google有网友给的答案是说更新cxf到最新版本,这下我可很慌啊,心里嘀咕更新了搞不好引入新的bug那就呵呵了,而且lib都是在本地,不是通过maven管理的,这期间难免会出现包缺失的bug
算了,还是老实点先看看cxf3.3.2里的sample吧
咦,人家是这样写的
@XmlType(name = "IntegerUserMap")
@XmlAccessorType(XmlAccessType.FIELD)
public class IntegerUserMap {
@XmlElement(nillable = false, name = "entry")
List<IntegerUserEntry> entries = new ArrayList<>();
public List<IntegerUserEntry> getEntries() {
return entries;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "IdentifiedUser")
static class IntegerUserEntry {
//Map keys cannot be null
@XmlElement(required = true, nillable = false)
Integer id;
User user;
public void setId(Integer k) {
id = k;
}
public Integer getId() {
return id;
}
public void setUser(User u) {
user = u;
}
public User getUser() {
return user;
}
}
}
为什么人家有xml相关的一坨注解,我的model里任何注解都没有,只在文件上传部分有个
@XmlMimeType("application/octet-stream")
private DataHandler file;
还是跟着官方走,加上后长这样了
@XmlType(name = "CxfFileHandler")
@XmlAccessorType(XmlAccessType.FIELD)
public class CxfFileHandler implements Serializable {
@XmlElement(required = true, nillable = false)
private String fileName;
@XmlElement
private String fileExt;
@XmlElement(required = true, nillable = false)
@XmlMimeType("application/octet-stream")
private DataHandler file;
......
}
再打包,ok了,谢天谢地
3. 本地代码生成
通过
wsdl2java http://xxx/createService?wsdl
生成的代码,发现方法参数都变成了arg0...
通用参考官方sample,
我擦,要写的这么复杂吗(只是第一感觉)
@WebService(targetNamespace = "http://cxf.apache.org/mime", name = "TestMtomPortType")
@XmlSeeAlso({org.apache.cxf.mime.types.ObjectFactory.class})
public interface TestMtomPortType {
@WebMethod
@RequestWrapper(localName = "testDataHandler", targetNamespace = "http://cxf.apache.org/mime/types", className = "org.apache.cxf.mime.types.DataHandlerType")
@ResponseWrapper(localName = "testDataHandlerResponse", targetNamespace = "http://cxf.apache.org/mime/types", className = "org.apache.cxf.mime.types.DataHandlerType")
public void testDataHandler(
@WebParam(mode = WebParam.Mode.INOUT, name = "name", targetNamespace = "http://cxf.apache.org/mime/types")
javax.xml.ws.Holder<java.lang.String> name,
@WebParam(mode = WebParam.Mode.INOUT, name = "attachinfo", targetNamespace = "http://cxf.apache.org/mime/types")
javax.xml.ws.Holder<javax.activation.DataHandler> attachinfo
);
@WebMethod
@RequestWrapper(localName = "testByteArray", targetNamespace = "http://cxf.apache.org/mime/types", className = "org.apache.cxf.mime.types.ByteArrayType")
@ResponseWrapper(localName = "testByteArrayResponse", targetNamespace = "http://cxf.apache.org/mime/types", className = "org.apache.cxf.mime.types.ByteArrayType")
public void testByteArray(
@WebParam(mode = WebParam.Mode.INOUT, name = "name", targetNamespace = "http://cxf.apache.org/mime/types")
javax.xml.ws.Holder<java.lang.String> name,
@WebParam(mode = WebParam.Mode.INOUT, name = "attachinfo", targetNamespace = "http://cxf.apache.org/mime/types")
javax.xml.ws.Holder<byte[]> attachinfo
);
}
是不是多了一些注解,比如@XmlSeeAlso,@WebMethod,@ResponseWrapper,@WebParam,一般ws开发就一个@WebService搞定一切,
再,其实很明显,要想保留数名,用@WebParam即可,至于其他注解,先不追究了(记性不好,学习了不用也会忘掉,如有高手还望发表评论指教在下,万般感谢!!)
最后
解决问题的过程是煎熬难过的,
问题解决了心情是愉悦舒畅,富有成就感的,
程序员之间多多鼓励,不要互相伤害,共勉!
多谢您的阅读,完