由於xfire的支持庫中是以spring1.2.6.jar 作爲spring 的支持庫所以這種方式不能正常的集成.
所以:
1: 刪除xfire下的spring1.2.6. jar再加入spring2的支持庫。
2:在web.xml中編寫如下代碼
<!-- 配置文件路徑 開始-->
|
classpath:org/codehaus/xfire/spring/xfire.xml是一定要加入到context-param中的.
3: 編寫服務的接口和具體的實現類.舉例如下:
package com.wujianjun.xfire.spring;
import java.util.List;
import com.wujianjun.xfire.domain.Person;
public interface IPersonService {
Person getMyInfo(String name);
String sayHello(String name);
List<Person> getPersons(String name);
}
package com.wujianjun.xfire.spring;
import java.util.ArrayList;
import java.util.List;
import com.wujianjun.xfire.domain.Person;
public class PersonServiceImpl implements IPersonService {
private String job;
public void setJob(String job) {
this.job = job;
}
@Override
public Person getMyInfo(String name) {
Person res = new Person();
res.setJob(job);
res.setName(name);
return res;
}
@Override
public String sayHello(String name) {
return "你好: "+name+",job="+job;
}
@Override
public List<Person> getPersons(String name) {
List<Person> res = new ArrayList<Person>();
Person p = new Person();
p.setJob("賣餅的");
p.setName("大郎");
res.add(p);
p = new Person();
p.setJob("賣水的");
p.setName(name);
res.add(p);
return res;
}
}
4: 編寫applicationContext.xml文件在裏面進行配置:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd" > <beans> <bean id="personService" class="com.wujianjun.xfire.spring.PersonServiceImpl"> <property name="job" value="JAVA" /> </bean> <bean name="PersonService" class="org.codehaus.xfire.spring.ServiceBean" > <property name="serviceBean" ref="personService" /> <property name="serviceClass" value="com.wujianjun.xfire.spring.IPersonService" /> </bean> </beans> |
5:發佈程序,啓動服務器訪問http://localhost:8080/xfire/services/則可以看到我們發佈的服務。如果我們做了配置而沒有顯示服務,我們要看一下我們applicationContext.xml裏面的bean 是否有lazy-init="false"的。如果有,則我們要把以上的服務配置改成
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd" > <beans> <bean id="personService" class="com.wujianjun.xfire.spring.PersonServiceImpl" lazy-init="false"> <property name="job" value="JAVA" /> </bean> <bean name="PersonService" class="org.codehaus.xfire.spring.ServiceBean" lazy-init="false"> <property name="serviceBean" ref="personService" /> <property name="serviceClass" value="com.wujianjun.xfire.spring.IPersonService" /> </bean> </beans> |
點擊旁邊的wsdl則可以訪問到對應的wsdl文件了。
再通過我們前面的調用就可以了。
如果有複雜類型的返回值,則要在對應接口的同一個包下建立一個InterfaceName.aegis.xml文件其對應的寫法如下:
*.aegis.xml文件的方法映射編寫
1、void setList(int id ,java.util.List,boolean persist);
<method name="setList" >
<parameter index="1" componentType="java.lang.String" />
<parameter index="2" class="boolean" />
</method>
2、Collection getCollection();
<method name= "getCollection" >
<return-type componentType="java.lang.Double" />
</method>
3、Map getGiftList() ;
<method name= "getGiftList" >
<return-type keyType= "org.codehaus.xfire.NiceChild" componentType= "org.codehaus.xfire.Present" >
</method>
4、 public List getListOfListOfDoubles {
List l = new ArrayList();
List doubles = new ArrayList();
doubles.add(new Double (1.0));
l.add(doubles);
return l;
}
<mapping>
<method name= "getListofListofDoubles" >
<return-type componentType="#someDoubles" />
</method>
<component name="someDoubles" class="java.util.List" componentType="java.lang.Double" />
</mapping>