1.框架集成Webservice
https://www.oschina.net/p/spring-shiro-training 这个项目增加集成Webservice功能,参考 http://blog.csdn.net/hbsong75/article/details/41207585 ,但是修正了以下几点
1.1 pom.xml中添加依赖包
要按照下面的格式,按照上面链接中的方法没有调通
<!--cxf webservice 集成配置 -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
1.2 版本号
版本号注意要填写3.0.3,我用了其他的版本jar包下载不下来
<cxf.version>3.0.3</cxf.version>
1.3 在web.xml文件中添加servlet
<servlet>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
1.4 spring-cxf.xml
spring目录下spring-cxf.xml文件中的内容这样填写,指明要发布的webservice
<jaxws:server id="mobileService" address="/mobile">
<jaxws:serviceBean>
<ref bean="mobileServiceImpl"/>
</jaxws:serviceBean>
</jaxws:server>
<bean id="mobileServiceImpl" class="com.wangzhixuan.webservice.impl.MobileServiceImpl"/>
结合前面web.xml指定的路径,则webservice的访问地址为http://localhost:8080/项目名/services/mobile?wsdl
这样还是不能访问,需要在拦截器中把webservice访问放行
1.5 不要让Shiro拦截Webservice
/services = anon <!-- webservice的链接不需要进行认证 -->
/services/** = anon <!-- webservice ws后面的所有链接都不进行认证 -->
2.添加JSON包
项目中可能还需要打包和解析JSON数据,maven中增加相关jar包。pom.xml中这样填写
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
注意:JDK版本要填写jdk15,虽然我的项目用的是JDK7。