在将服务层公开为webservice之后,服务层注入不起作用

时间:2012-01-10 14:11:24

标签: java spring jax-ws

我有一个服务类通过DAO类进行数据库操作,我使用spring注入DAO对象。它工作正常。

之后,我使用JAX-WS注释公开了与webservice方法相同的方法。

之后它没有工作它说我的dao对象没有被注入,所以我得到nullpointerexception。我正在做的方式是否正确?

我的服务类是

package com.tecnotree.upc.services.impl;

import com.tecnotree.upc.services.*;
import com.tecnotree.upc.entities.*;
import com.tecnotree.upc.dao.UpcLineOfBusinessDao;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.WebParam;
import javax.jws.soap.SOAPBinding;

import org.springframework.transaction.annotation.Transactional;
@WebService
@SOAPBinding(style=SOAPBinding.Style.DOCUMENT,use=SOAPBinding.Use.LITERAL,
            parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)
public class UpcLineOfBusinessServiceImpl implements UpcLineOfBusinessService {
    private UpcLineOfBusinessDao upcLineOfBusinessDao;

    public void setUpcLineOfBusinessDao(
            UpcLineOfBusinessDao upcLineOfBusinessDao) {
        this.upcLineOfBusinessDao = upcLineOfBusinessDao;
    }

    @Override
    @Transactional
    @WebMethod
    public UpcLineOfBusinessEntity createUpcLineOfBusinessEntity(
            UpcLineOfBusinessEntity upcLineOfBusinessEntity) {
        try{
        if(upcLineOfBusinessDao!=null)
            return upcLineOfBusinessDao.create(upcLineOfBusinessEntity);
        else
            return null;
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
            return null;
        }


    }

}

我的spring xml文件是

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

<bean id="upcDataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName" value="oracle.jdbc.OracleDriver" />
    <property name="url" value="jdbc:oracle:thin:@192.168.4.33:1521:lt33" />
    <property name="username" value="UPC_PROD" />
    <property name="password" value="UPC_PROD" />
</bean>
<bean id="upcSessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="upcDataSource" />
    <property name="mappingResources">
        <list>
            <value>/com/tecnotree/upc/hbmfiles/UpcLineOfBusinessEntity.hbm.xml
            </value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
        </props>
    </property>
</bean>
<bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory">
        <ref bean="upcSessionFactory" />
    </property>
</bean>

<tx:annotation-driven />

<bean id="upcLineOfBusinessDao" class="com.tecnotree.upc.dao.impl.UpcLineOfBusinessDaoImpl">
    <property name="sessionFactory">
        <ref bean="upcSessionFactory" />
    </property>
</bean>
<bean id="upcLineOfBusinessService" class="com.tecnotree.upc.services.impl.UpcLineOfBusinessServiceImpl">
    <property name="upcLineOfBusinessDao">
        <ref bean="upcLineOfBusinessDao" />
    </property>
</bean>

1 个答案:

答案 0 :(得分:0)

我通过在服务类中扩展SpringBeanAutowiringSupport来解决这个问题。现在工作正常。感谢您的所有意见