ws问题总结(二)
来源:互联网 发布:清除软件残留 编辑:程序博客网 时间:2024/05/16 05:47
1、a > 建一个web项目,添加完spring+hibernate的jar包以后,添加jax-ws 2.1等jar路径;
b > 然后写一个java类,带上@WebService和@WebMethod,
c > 使用Myeclipse自动生成WS,会自动生成wsdl、web.xml中的配置等,applicationContext.xml中不用额外配置;
(加上@,则不会生成TgsFuncitonDelegate)
d > 在spring中,toTell中注入private WSAction wsaction,wsaction使用时报空指针,实例化toTell时wsaction没有注入成功,需要这样得到wsaction
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
WSAction wsaction= (TgsPassedCarAction)context.getBean("WSAction");
e > (jar包:spring +
hibernate +
jax-ws 2.1 RunTime Liberaries +
jax-ws 2.1 API Liberaries)
----------------------------------------------------------web.xml中自动生成的部分---------------------------------------------------------------------------------------------------------
-------------------------------------还有记得是WSServlet,不要和后边的WSSpringServlet混了----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?><web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <display-name></display-name> <span style="color:#ff0000;"> <listener> <listener-class> com.sun.xml.ws.transport.http.servlet.WSServletContextListener </listener-class> </listener></span> <servlet> <description>JAX-WS endpoint - toDoService</description> <display-name>toDoService</display-name> <servlet-name>toDoService</servlet-name> <servlet-class> <span style="color:#ff0000;">com.sun.xml.ws.transport.http.servlet.WSServlet</span> </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>toDoService</servlet-name> <url-pattern>/toDoPort</url-pattern> </servlet-mapping></web-app>
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2、通过spring注入的方式,而不用再context.getBean()的方式获得注入的bean组件,更加方便
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
a > 首先加上Spring+jax-ws整合所需要的jar包,见下面,spring和hibernate的jar包随意加;
b > 写一个java类,要加上@WebService(targetNamespace = "org.coderecord.blog"),括号里的没加的话,我这里报错(Caused by: com.sun.xml.ws.model.RuntimeModelerException: 必须在没有程序包的类上指定 @WebService.targetNamespace。类: Test);
@WebMethod(exclude = true)使get/set方法对外不可见;
<p>import javax.jws.WebMethod;import javax.jws.WebService;</p><p>@WebService(targetNamespace = "org.coderecord.blog")public class Test { private TestBean testBean; @WebMethod public String toTest(String name){ String daming = testBean.tosat("lvlvlv"); System.out.println(name+": "+daming); return name+":"+daming; } @WebMethod(exclude = true) public TestBean getTestBean() { return testBean; } @WebMethod(exclude = true) public void setTestBean(TestBean testBean) { this.testBean = testBean; }}</p>
c > 接着,applicationContext.xml中,手动配置
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <span style="color:#ff0000;">xmlns:ws="http://jax-ws.dev.java.net/spring/core"</span> <span style="color:#ff0000;"> xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"</span> xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd <span style="color:#ff0000;"> http://jax-ws.dev.java.net/spring/core http://jax-ws.dev.java.net/spring/core.xsd http://jax-ws.dev.java.net/spring/servlet http://jax-ws.dev.java.net/spring/servlet.xsd"></span> <bean id="test" class="Test"> <property name="testBean"> <ref bean="testBean"/> </property> </bean> <bean id="testBean" class="TestBean"></bean> <span style="color:#ff0000;"> <wss:binding url="/service/test"> <wss:service> <ws:service bean="#test" /> </wss:service> </wss:binding></span></beans>
d > web.xml中手动配置,注意下面红色的代码和第一种jax-ws写法中的WSServlet 不是一个Servlet
<?xml version="1.0" encoding="UTF-8"?><web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <display-name></display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/classes/*Context.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <description>JAX-WS endpoint - test</description> <display-name>testService</display-name> <servlet-name>testService</servlet-name> <span style="color:#ff0000;"><servlet-class>com.sun.xml.ws.transport.http.servlet.WSSpringServlet</servlet-class></span> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>testService</servlet-name> <url-pattern>/service/test</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list></web-app>
- ws问题总结(二)
- ws问题总结(三)
- WS问题总结
- JAX-WS(二)- client
- WS安全性问题(2)
- (二) WebService-- JDK 发布WS服务
- (二) CXF 发布WS服务
- 使用jax-ws开发webservice(二)
- WS-Security 中文问题&Stax(Streaming API for XML) (二)
- jax-ws WebService相关问题(一)
- 疑问问题总结(二)
- 经典问题总结(二)
- Spring-WS(二)-入门
- WS服务总结
- JAVA6开发WebService (二)——JAX-WS例子
- JAVA6开发WebService (二)——JAX-WS例子
- webservice快速入门-使用wsimport生成ws服务端(二)
- JAVA6开发WebService (二)——JAX-WS例子
- Sicily 1937. 导游
- ios Objective-C Runtime运行时类与对象的编译处理(写的很好,值得阅读)
- UrbanCode Deploy 常用操作
- 网关协议学习:CGI、FastCGI、WSGI
- (转)被误解的 Node.js
- ws问题总结(二)
- silverlight 弹窗定位到线的方法
- 菜鸟进阶之Android Touch事件传递(四)
- Obtain a SAML Token ----获取SAML令牌
- VC6.0 error LNK2001: unresolved external symbol _main解决办法
- Request
- uva11624
- POJ 2774 Long Long Message(最长公共子串 -初学后缀数组)
- iOS开发多线程篇—线程的状态