Web services 调用WebService期间出错-无法初始化代理-无会话

Web services 调用WebService期间出错-无法初始化代理-无会话,web-services,apache,spring,hibernate,cxf,Web Services,Apache,Spring,Hibernate,Cxf,应用程序:Spring+Hibernate+apachecxf-idea simple say hello服务,它获取数据库中对象的一个参数id,并返回文本“hello:”+person.getName() 以下是一些代码: @Entity public class Person { @Id @GeneratedValue(strategy=GenerationType.AUTO) private long id; private String login;

应用程序:Spring+Hibernate+apachecxf-idea simple say hello服务,它获取数据库中对象的一个参数id,并返回文本“hello:”+person.getName()

以下是一些代码:

@Entity
public class Person {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private long id;

    private String login;

    private String email;
//getters and setters
}
潘松道: 公共接口PersonDAO{ 公共无效储户(人); 公众人物getPerson(长id); }

个人建议:

@Repository
@Transactional
public class PersonDAOImpl implements PersonDAO {

    @Autowired
    private SessionFactory sessionFactory;

    public void savePerson(Person person) {
        sessionFactory.getCurrentSession().save(person);
    }

    public Person getPerson(long id){
        Hibernate.initialize(sessionFactory);
        return (Person) sessionFactory.getCurrentSession().load(Person.class, id);
    }
}
PersonWebService:

@WebService
public interface PersonWebService {
    public String sayHello(long id);
}
PersonWebServiceImpl:

@WebService(endpointInterface="com.robert.example.testowy.webservices.PersonWebService")
public class PersonWebServiceImpl implements PersonWebService{

    @Autowired
    private PersonDAO personDAO;

    public String sayHello(long id) {
        Person person = personDAO.getPerson(id);
        return "Hello: " + person.getLogin();
    }

}
和来自xml的数据源配置(DataSource,sessionFactory):


com.robert.example.testowy.domain
org.hibernate.dialogue.mysqldialogue
符合事实的
创造

我已经找到了一些解决办法,但对我来说不起作用。我非常感谢任何帮助建议和解决方案。

好的,我找到了我犯错误的地方。。。在我的例子中,WebService方法sayHello应该是事务性的。。。在sayHello上添加注释@Transactional后,效果良好。

事务从何处开始?我在PersonWebServiceImpl中没有看到任何与事务相关的注释?PaersonDAO被标记为TTansAction。
<context:annotation-config />

    <context:component-scan base-package="com.robert.example.testowy" />


    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
        p:driverClassName="com.mysql.jdbc.Driver"
        p:url="jdbc:mysql://localhost:3306/edyplom"
        p:username="root"
        p:password="sedes" />

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan">
            <value>com.robert.example.testowy.domain</value>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">create</prop>
            </props>
        </property>
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager"/>
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>