MyEclipse on SPRING+MYBATIS+AXIS2 issue of WebService interface and how to implement it personally

Source: Internet
Author: User

Premise:

This month of a sudden day, there is a project docking needs to use Axis2 published interface, this baffled me, after all, I was even WebService interface did not know how to publish. The first interface was later released from HelloWorld--sayhi (); It was a smooth step, but with AXIS2 integration, there was a problem, and spring's DAO layer was always null in the interface after Axis2 was released, It seems that spring has not been initialized, during which I tested in accordance with the normal process to execute a request, is correct, and AXIS2 integration is not, in this test time, very painful, very painful, all can think of the method has been tried, including the mandatory acquisition of DAO and Singleton mode, But then the egg. So had to retreat and beg second, first use SPRING+MYBATIS+CXF to publish a can use the interface as a proxy, and then use the Axis2 frame to publish a separate call agent method to achieve project docking. Here's how to start spring+mybatis+cxf:

One, create the project catalog:

First, we build an entity class Person.java

 PackageCom.srit.user.model; Public classPerson {PrivateString ID; PrivateString name; Private intAge ; PrivateString birthday; Private Doublehight;  PublicString getId () {returnID; }       Public voidsetId (String id) { This. ID =ID; }       PublicString GetName () {returnname; }       Public voidsetName (String name) { This. Name =name; }       Public intGetage () {returnAge ; }       Public voidSetage (intAge ) {           This. Age =Age ; }       PublicString Getbirthday () {returnbirthday; }       Public voidsetbirthday (String birthday) { This. Birthday =birthday; }       Public Doublegethight () {returnhight; }       Public voidSethight (Doublehight) {           This. hight =hight; }  }

Then we first write the DAO in the Persondao.java, it is an interface interface, mainly to perform a simple increase, delete, change, check

 PackageCom.srit.user.dao;Importjava.util.List;ImportJavax.jws.WebMethod;ImportJavax.jws.WebService;ImportCom.srit.user.model.Person; Public InterfacePersondao { Public voidInsertPerson (person person);  Public voidUpdateperson (person person);  PublicList<person>Findperson (String name);  Public voidDeleteperson (String ID); }

The following is the implementation class of the DAO layer Persondaoimpl.java

1  PackageCom.srit.user.dao.impl;2 3 Importjava.util.List;4 5 ImportJavax.annotation.Resource;6 7 Importorg.mybatis.spring.SqlSessionTemplate;8 ImportOrg.mybatis.spring.support.SqlSessionDaoSupport;9 Ten ImportCom.srit.user.dao.PersonDao; One ImportCom.srit.user.model.Person; A  -  Public classPersondaoimplextendsSqlsessiondaosupportImplementsPersondao { -  the     Privatesqlsessiontemplate sqlsessiontemplate;  -      -      Publicsqlsessiontemplate getsqlsessiontemplate () { -         returnsqlsessiontemplate;  +     }   -    +@Resource (name= "Sqlsessiontemplate")     A      Public voidsetsqlsessiontemplate (sqlsessiontemplate sqlsessiontemplate) { at          This. sqlsessiontemplate =sqlsessiontemplate;  -     }   -    -      Public voidDeleteperson (String id) { -Getsqlsession (). Delete ("Com.srit.usr.dao.PersonDao.deletePerson", id);  -     }   in    -      PublicList<person>Findperson (String name) { to         returnGetsqlsession (). SelectList ("Com.srit.user.dao.PersonDao.findPerson", name);  +     }   -    the      Public voidInsertPerson (person person) { *Getsqlsession (). Insert ("Com.srit.user.dao.PersonDao.insertPerson", person);  $     }  Panax Notoginseng    -      Public voidUpdateperson (person person) { theGetsqlsession (). Update ("Com.srit.user.dao.PersonDao.updatePerson", person);  +     }   A    the  +}

Then the service layer Personservice.java

 PackageCom.srit.user.service;Importjava.util.List;ImportCom.srit.user.model.Person; Public InterfacePersonservice { Public voidInsertPerson (person person);  Public voidUpdateperson (person person);  PublicList<person>Findperson (String name);  Public voidDeleteperson (String ID);}

followed by the service Layer implementation class Personserviceimpl.java

 PackageCom.srit.user.service.impl;Importjava.util.List;ImportJavax.annotation.Resource;ImportOrg.springframework.stereotype.Service;Importorg.springframework.transaction.annotation.Transactional;ImportOrg.springframework.web.context.ContextLoader;ImportOrg.springframework.web.context.WebApplicationContext;ImportCom.srit.user.dao.PersonDao;ImportCom.srit.user.model.Person;ImportCom.srit.user.service.PersonService, @Service @Transactional Public classPersonserviceimplImplementsPersonservice {@ResourcePrivatePersondao Persondao;  PublicPersondao Getpersondao () {returnPersondao; }       Public voidSetpersondao (Persondao Persondao) { This. Persondao =Persondao; //Webapplicationcontext Context=contextloader.getcurrentwebapplicationcontext ();//Persondao = (Persondao) context.getbean ("Persondao");    }         Public voidDeleteperson (String id) {Persondao.deleteperson (ID); }         PublicList<person>Findperson (String name) {returnPersondao.findperson (name); }         Public voidInsertPerson (person person) {Persondao.insertperson (person); }         Public voidUpdateperson (person person) {Persondao.updateperson (person); }    }

And then there's the service interface we're going to publish. Mywebservice.java

1  Package Com.srit.user.webservice; 2 3 Import Com.srit.user.model.Person; 4 5  Public Interface MyWebService {6      Public  7 }

Of course must have its implementation class Mywebserviceimpl.java

Off the clock ... Next time, write.

MyEclipse on SPRING+MYBATIS+AXIS2 issue of WebService interface and how to implement it personally

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.