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

Web Service實例(Spring+Hibernate+Web Servic

系統 2087 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 ;

?????? }

??? }

}

?

業務層類 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( " 根據 id 得到論壇配置對象時發生錯誤,具體內容為: " , e);

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

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

?????? }

?????? return configVO;

??? }

}

?

創建 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

?

創建 Web Service 如下圖所示:

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

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

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

點擊“ Finish ”即完成了 Web Service 的創建。

此時啟動 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 的創建。

?

新建一個測試類如下,

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 目錄則新建下。否則會出現 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)


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

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

【本文對您有幫助就好】

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

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 南通市| 玛多县| 徐闻县| 金华市| 罗平县| 阿克苏市| 宜兴市| 乐平市| 五台县| 轮台县| 礼泉县| 肇东市| 高碑店市| 潮安县| 枣庄市| 鸡泽县| 灵台县| 资兴市| 彰化市| 台北县| 丰台区| 德格县| 黄平县| 扬中市| 措美县| 宽城| 新源县| 建德市| 沧州市| 扬中市| 霍林郭勒市| 海兴县| 富宁县| 桃园市| 周至县| 灌阳县| 内江市| 天全县| 海阳市| 屏边| 谷城县|