在開源中國上發(fā)現(xiàn)一個(gè)簡單好用的集成框架旷痕,地址:https://www.oschina.net/p/spring-shiro-training ,項(xiàng)目中已經(jīng)有了基本的權(quán)限管理,正好手頭有一個(gè)小型的項(xiàng)目,于是直接在這個(gè)基礎(chǔ)上開發(fā)朽寞。
1. 開發(fā)環(huán)境搭建
開發(fā)環(huán)境:JKD7+Tomcat7+Eclipse4.4+MySQL
運(yùn)行源代碼提示如下錯(cuò)誤:
解決辦法:
在pom.xml中添加下面的依賴
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
參考:http://xyly624.blog.51cto.com/842520/859833
2. 框架集成Webservice
我的項(xiàng)目需要增加集成Webservice功能,直接參考這個(gè)地址( http://blog.csdn.net/hbsong75/article/details/41207585 )進(jìn)行配置斩郎,沒有成功脑融,可能是我的開發(fā)環(huán)境與文章作者的環(huán)境有些差別。又經(jīng)過半天的努力終于配置好了缩宜,記錄過程如下:
2.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>
2.2 版本號
cxf 版本號注意要填寫3.0.3肘迎,我用了其他的版本jar包下載不下來
<cxf.version>3.0.3</cxf.version>
2.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>
2.4 spring-cxf.xml
spring目錄下spring-cxf.xml文件中的內(nèi)容這樣填寫,指明要發(fā)布的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"/>
結(jié)合前面web.xml指定的路徑锻煌,則webservice的訪問地址為http://localhost:8080/項(xiàng)目名/services/mobile?wsdl
這樣還是不能訪問宋梧,需要在攔截器中把webservice訪問放行
2.5 不要讓Shiro攔截Webservice
/services = anon <!-- webservice的鏈接不需要進(jìn)行認(rèn)證 -->
/services/** = anon <!-- webservice ws后面的所有鏈接都不進(jìn)行認(rèn)證 -->
3.添加JSON包
我的項(xiàng)目中還需要打包和解析JSON數(shù)據(jù)肛著,maven中增加相關(guān)jar包跺讯。pom.xml中這樣填寫
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
注意:JDK版本要填寫jdk15,雖然我的項(xiàng)目用的是JDK7殉农。