本文介绍如何在WebLogic下通过利用Spring和CXF框架进行发布WebService
其实大家想想看,上篇文章写的同样的框架只不过不同之处在于,tomcat和WebLogic的区别
但是期间出现的问题不可小觑啊,下面来简单的分析了解一下吧:
1...........................目录架构图
来个找茬游戏呵呵 左图是在Tomcat服务器下面进行发布的,右图是在WebLogic下进行部署的呵呵,看到区别没啊
除了红色字体注释,还有什么区别===对了工程名不一样了,这说明我们这是两个工程了,还有吗.........................当然没了啊,因为除了web.xml,其它的我都是直接copy过来的
2...............................看看这次Web.xml的配置
其实不是两次web.xml不同,只不过这次我采用了另外一种方式进行配置框架,想把sping和cxf分的更清楚一点
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<!--spring需要加载的配置文件-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- **************** CXF configuration *****************-->
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
大家一目了然,是不是耦合更加明了了吧(其实是我对依赖感到不耐烦)
3......................运行就OK了
http://localhost:7001/WebLogicProj/services/hello?wsdl ...............................................注意端口的区别,webLogic是7001
4...................看到和上篇文章一样的结果,你就可以庆祝一下了(呵呵)
5........................可能出现的异常信息"No bean named 'cxf'
这是由于没有添加 services.xml中的
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
6...................可能出现的异常缺少bean文件
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location
[applicationContext-cxf.xml]
Offending resource: URL
[file:/D:/software_tool/tomcat/apache-tomcat-6.0.16/apache-tomcat-6.0.16/webapps/ManagementFrontEndWeb/WEB-INF/classes/spring/applicationContext.xml];
nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from
URL [file:/D:/software_tool/tomcat/apache-tomcat-6.0.16/apache-tomcat-6.0.16/webapps/ManagementFrontEndWeb/WEB-INF/classes/spring/applicationContext-cxf
.xml]; nested exception is org.springframework.beans.FatalBeanException: Invalid NamespaceHandler class [org.apache.cxf.jaxws.spring.NamespaceHandler] for
namespace [http://cxf.apache.org/jaxws]: problem with handler class file or dependent class; nested exception is java.lang.NoClassDefFoundError:
javax/xml/stream/XMLStreamWriter
解决方法:出现该错误是jdk的编译环境出现问题,有2中解决办法1.window——>preferences------>myeclipse------>servers----->Tomcat----->tomcat6.x----->jdk添加com.sun.java.jdk.win32.x86_1.6.0.013即可,注意:该方法与你安装的编译环境有关系。(myeclipse8.0)
2.添加3个jar包,分别是:geronimo-jaxws_2.1_spec-1.0.jar,ojdbc14.jar,jaxb-api-2.1.jar(Myeclipse6.0)
这里引用http://blog.csdn.net/snowyz/article/details/5258150博主的博文,在此表示感谢