【发布时间】:2012-01-10 14:11:24
【问题描述】:
我有一个服务类通过 DAO 类执行 DB 操作,我使用 spring 注入 DAO 对象。它工作正常。
之后,我使用 JAX-WS 注释公开了与 Web 服务方法相同的方法。
之后它不起作用,它说我的 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>
【问题讨论】:
-
请提供部分相关代码
-
你不能通过添加注解把一个dao变成一个webservice,一个web service必须对应一个wsdl,你应该基于一个在线的wsdl自动生成你的WS客户端。
-
你需要告诉我们空指针异常是在哪里抛出的,我们无从猜测。
-
在这一行 upcLineOfBusinessDao.create(upcLineOfBusinessEntity);我得到空指针异常。无论如何要解决这个问题?请帮帮我
-
是否需要在我的服务层中使用 SpringBeanAutowiringSupport 类?