iteye_16422
iteye_16422
2011-08-15 10:43

关于apache cxf 结合Spring框架开发webservice服务

已采纳

我在用apache cxf 结合Spring框架开发webservice服务时,遇到一个这样的问题,请大家帮忙解决一下,问题描述如下:

webservice启动配置如下
Java代码
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

<import resource="classpath:META-INF/cxf/cxf.xml" />  
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />  
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />    
<jaxws:endpoint id="sqlExecuteService"  
    implementor="com.unicom.uniformdata.SqlExecuteServiceImpl"        
    address="/DesServer">      
</jaxws:endpoint>  

com.unicom.uniformdata.SqlExecuteServiceImpl类实现如下
Java代码
@javax.jws.WebService(

serviceName = "SqlExecuteServiceService",

portName = "SqlExecuteServicePort",

targetNamespace = "http://uniformdata.unicom.com",

endpointInterface = "com.unicom.uniformdata.SqlExecuteService")

public class SqlExecuteServiceImpl implements SqlExecuteService {

private DaoHelper daoHelper = null;

public SqlExecuteServiceImpl() {  
    System.out.println("实例化webservice实现类");  
    this.daoHelper =  GlobalVariable.getInstance().getDaoHelper();        
}  

}

public DaoHelper getDaoHelper() {

return this.daoHelper == null ? (this.daoHelper = (DaoHelper) SpringUtils.getBean("daoHelper")): this.daoHelper;

}

其中daoHelper类的配置是通过配置的,是数据库操作对象。但在Tomcat启动时,是先实例化SqlExecuteServiceImpl,而不是daoHelper,导致SqlExecuteServiceImpl实例化失败,webservice服务启动失败。这个问题怎么解决。对cxf框架也不是很熟,希望大家能帮助解决一下,谢谢!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • cwx714 紫翎观星 10年前

    构造器改写静态语句块:
    [code="java"]
    static {
    System.out.println("实例化webservice实现类");
    this.daoHelper = GlobalVariable.getInstance().getDaoHelper();

    }
    [/code]

    点赞 评论 复制链接分享

相关推荐