User类:
public class User {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public interface UserService {
public User getUser();
}
实现类:
public class UserServiceImpl implements UserService {
public User getUser(){
User u = new User();
u.setName("test");
return u;
}
}
web.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>XFireServlet</servlet-name>
<servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>XFireServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
applicationContext.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />
<!-- base service -->
<bean id="webService" class="org.codehaus.xfire.spring.remoting.XFireExporter" lazy-init="false"
abstract="true">
<property name="serviceFactory" ref="xfire.serviceFactory" />
<property name="xfire" ref="xfire" />
<property name="scope" value="application"/>
<property name="use" value="literal"/>
<property name="style" value="wrapped"/>
</bean>
<bean id="userService" parent="webService">
<property name="serviceBean" ref="userServiceImpl" />
<property name="serviceClass" value="UserService" />
<property name="name" value="UserService"/>
</bean>
<bean id="userServiceImpl" class="UserServiceImpl"/>
</beans>
客户端调用代码:
public static void main(String[] args) {
Service srvcModel = new ObjectServiceFactory()
.create(UserService.class);
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
.newInstance().getXFire());
String url= "http://localhost:8080/ws/services/UserService";
try {
UserService srvc = (UserService) factory.create(
srvcModel, url);
User u= srvc.getUser();
System.out.println(u.getName());
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
打印出来的结果为:null
理论上来说USER类里面,只有String这样的基本类型,不要什么映射就可以了,但是还得不到值,百思不得其解,期待那个高*手指点指点....多谢!!!
public class User {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public interface UserService {
public User getUser();
}
实现类:
public class UserServiceImpl implements UserService {
public User getUser(){
User u = new User();
u.setName("test");
return u;
}
}
web.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>XFireServlet</servlet-name>
<servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>XFireServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
applicationContext.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />
<!-- base service -->
<bean id="webService" class="org.codehaus.xfire.spring.remoting.XFireExporter" lazy-init="false"
abstract="true">
<property name="serviceFactory" ref="xfire.serviceFactory" />
<property name="xfire" ref="xfire" />
<property name="scope" value="application"/>
<property name="use" value="literal"/>
<property name="style" value="wrapped"/>
</bean>
<bean id="userService" parent="webService">
<property name="serviceBean" ref="userServiceImpl" />
<property name="serviceClass" value="UserService" />
<property name="name" value="UserService"/>
</bean>
<bean id="userServiceImpl" class="UserServiceImpl"/>
</beans>
客户端调用代码:
public static void main(String[] args) {
Service srvcModel = new ObjectServiceFactory()
.create(UserService.class);
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
.newInstance().getXFire());
String url= "http://localhost:8080/ws/services/UserService";
try {
UserService srvc = (UserService) factory.create(
srvcModel, url);
User u= srvc.getUser();
System.out.println(u.getName());
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
打印出来的结果为:null
理论上来说USER类里面,只有String这样的基本类型,不要什么映射就可以了,但是还得不到值,百思不得其解,期待那个高*手指点指点....多谢!!!