日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

Web Service實例(Spring+Hibernate+Web Servic

系統(tǒng) 2243 0

一、新建 Web Service Project ,如下圖所示: Web Service實例(Spring+Hibernate+Web Service)

點擊“ Finish ”后,引入所要用的 jar 包,本工程所用的 jar 包如下:

Web Service實例(Spring+Hibernate+Web Service)

其中 webservices-api.jar webservices-extra-api.jar webservices-extra.jar webservices-rt.jar 通過引入庫的方式引入,如下圖所示:

Web Service實例(Spring+Hibernate+Web Service)

持久層類 ConfigDAOImpl 代碼如下:

public class ConfigDAOImpl extends HibernateDaoSupport implements

?????? ConfigDAOInterface {

??? @SuppressWarnings ( "unchecked" )

??? public ConfigPO findById(String id ) {

?????? getHibernateTemplate().setCacheQueries( true );

??? getHibernateTemplate().setQueryCacheRegion( "org.bbsws.po.ConfigPO" );

?????? List<ConfigPO> list = getHibernateTemplate().find(

????????????? "from ConfigPO where ID=?" , id );

?????? if (list != null && list.size() > 0) {

?????????? return list.get(0);

?????? } else {

?????????? return null ;

?????? }

??? }

}

?

業(yè)務(wù)層類 ConfigServiceImpl 代碼如下:

public class ConfigServiceImpl implements ConfigServiceInterface {

??? private Log log = LogFactory. getLog (ConfigServiceImpl. class );

??? private ConfigDAOInterface configDao = null ;

?

??? public void setConfigDao(ConfigDAOInterface configDao) {

?????? this . configDao = configDao;

??? }

???

??? public ConfigVO findById(String id) throws BBSWSException {

?????? ConfigVO configVO = new ConfigVO();

?????? ConfigPO configPO = configDao .findById(id);

?????? try {

?????????? BeanUtils. copyProperties (configVO, configPO);

?????? } catch (IllegalAccessException e) {

?????????? log .error( " 根據(jù) id 得到論壇配置對象時發(fā)生錯誤,具體內(nèi)容為: " , e);

?????? } catch (InvocationTargetException e) {

?????????? log .error( " 根據(jù) id 得到論壇配置對象時發(fā)生錯誤,具體內(nèi)容為: " , e);

?????? }

?????? return configVO;

??? }

}

?

創(chuàng)建 Web Service 所使用的 Java Bean 如下:

public class ConfigWS {

??? private ConfigServiceInterface configServiceInterface = null ;

?

??? public ConfigWS() {

?????? configServiceInterface = BeanXMLFactory. getInstance ()

????????????? .getConfigService();

??? }

???

??? public ConfigVO findById(String id) throws BBSWSException {

?????? return configServiceInterface .findById(id);

??? }

}

?

由于 JAX-WS 不支持 Spring 注入,所以用 BeanXMLFactory 來得到 Spring 中配置的 Bean

?

創(chuàng)建 Web Service 如下圖所示:

Web Service實例(Spring+Hibernate+Web Service)

點擊“ Next ”,進行如下配置:

Web Service實例(Spring+Hibernate+Web Service)

點擊“ Finish ”即完成了 Web Service 的創(chuàng)建。

此時啟動 Tomcat ,輸入 http://localhost:8080/bbsws/ConfigWSPort 即可看配置是否成功。

?

?

二、新建 Web Project ,此處名為 bbs ,然后點擊“ New Web Service Client ”,如下圖所示:

? Web Service實例(Spring+Hibernate+Web Service)

點擊“ Next ”,如下:

Web Service實例(Spring+Hibernate+Web Service)

一直點擊“ Next ”到如下界面:

Web Service實例(Spring+Hibernate+Web Service)

點擊“ Finish ”即完成了 Web Service Client 的創(chuàng)建。

?

新建一個測試類如下,

public class Test {

??? public static void main(String[] args) throws BBSWSException_Exception {

?????? ConfigWSService service = new ConfigWSService();

?????? ConfigWSDelegate delegate = service.getConfigWSPort();

?????? ConfigVO configVO = delegate.findById( "AttachFileType" );

?????? System. out .println(configVO.getID() + ":" + configVO.getConfContext());

??? }

}

?

需要將 webservices-api.jar 拷貝到 MyEclipse 安裝目錄下的 jre\lib\endorsed 中,如果沒有 endorsed 目錄則新建下。否則會出現(xiàn) Exception in thread "main" java.lang.LinkageError: JAXB 2.0 API is being loaded from the bootstrap classloader, but this RI (from jar:file:/E:/software/Java/workstation/bbs/WebRoot/WEB-INF/lib/webservices-rt.jar!/com/sun/xml/bind/v2/model/impl/ModelBuilder.class) needs 2.1 API. Use the endorsed directory mechanism to place jaxb-api.jar in the bootstrap classloader. (See http://java.sun.com/j2se/1.5.0/docs/guide/standards/ ) 異常。

?

Web Service實例(Spring+Hibernate+Web Service)


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 舞阳县| 海兴县| 清徐县| 石狮市| 扎兰屯市| 寿光市| 胶南市| 平陆县| 临夏市| 灵宝市| 卓尼县| 连云港市| 军事| 将乐县| 天峻县| 松原市| 都昌县| 博罗县| 伊吾县| 宝山区| 许昌市| 安宁市| 玛纳斯县| 古田县| 陆川县| 乃东县| 福海县| 东丰县| 买车| 区。| 德江县| 长顺县| 雷山县| 祁东县| 阳信县| 喀喇沁旗| 张家口市| 名山县| 桑植县| 新昌县| 佛学|