Hello everyone, i got a problem
I use spring-cxf in a webservice project.
Server side:Spring+CXF+Hibernate
Client side:Spring+CXF
And I got a exception when my client send a request to server
Code:
org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
If i use jdbctemplate instead of hibernate, everything is OK.
Or if i don't use webservice, everything is OK.
springContext.xml
Code:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>/hbm/UserInfo.hbm.xml</value>
</list>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
<property name="nestedTransactionAllowed">
<value>true</value>
</property>
</bean>
<tx:advice id="txWorksysAdvice"
transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED"
rollback-for="Exception" />
</tx:attributes>
</tx:advice>
<aop:config proxy-target-class="true">
<aop:advisor
pointcut="execution(* com.test.services..*.*Service.*(..))"
advice-ref="txWorksysAdvice" />
</aop:config>
cxf-server.xml
Code:
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<jaxws:endpoint address="/testservice">
<jaxws:implementor ref="testService" />
</jaxws:endpoint>
<bean id="testService" class="com.test.ws.impl.TestServiceImpl" />
cxf-clent.xml
Code:
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<jaxws:client id="clientService" serviceClass="com.test.ws.TestService"
address="http://localhost:8080/testcxf/ws/testservice" />
My dao code
Code:
public Session getSession() {
return sessionFactory.getCurrentSession();
}
client code
Code:
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext(
"spring/haha-ws-client.xml");
SearchService sss = ctx.getBean(SearchService.class);
sss.insertData("字符abc123");
}
Anyone can help me ? thanks a lot.