Hi out there,
I'm want to set up a CXF 2.2.6 webservice with persistence using
hibernate on a tomcat 6.0.24.
my setup, please take a look at the attached files.
The same configuration work fine without CXF, I dont' know how to set up
this with CXF context, and wehre the problem is.
..
INFO ;2010-02-03
10:30:46,578;org.hibernate.impl.SessionFactoryObjectFactory;;Factory
name: MyHibernateSession
INFO ;2010-02-03 10:30:46,578;org.hibernate.util.NamingHelper;;JNDI
InitialContext properties:{}
INFO ;2010-02-03
10:30:46,578;org.hibernate.impl.SessionFactoryObjectFactory;;Bound
factory to JNDI name: MyHibernateSession
WARN ;2010-02-03
10:30:46,578;org.hibernate.impl.SessionFactoryObjectFactory;;InitialContext
did not implement EventContext
INFO ;2010-02-03
10:30:46,610;org.springframework.web.context.ContextLoader;;Root
WebApplicationContext: initialization started
INFO ;2010-02-03
10:30:46,633;org.springframework.web.context.support.XmlWebApplicationContext;;Refreshing
org.springframework.web.context.support.xmlwebapplicationcont...@3f56e5ed:
display name [Root WebApplicationContext]; startup date [Wed Feb 03
10:30:46 CET 2010]; root of context hierarchy
INFO ;2010-02-03
10:30:46,668;org.springframework.beans.factory.xml.XmlBeanDefinitionReader;;Loading
XML bean definitions from ServletContext resource
[/WEB-INF/applicationContext.xml]
INFO ;2010-02-03
10:30:46,737;org.springframework.beans.factory.xml.XmlBeanDefinitionReader;;Loading
XML bean definitions from class path resource [META-INF/cxf/cxf.xml]
INFO ;2010-02-03
10:30:46,800;org.springframework.beans.factory.xml.XmlBeanDefinitionReader;;Loading
XML bean definitions from class path resource
[META-INF/cxf/cxf-extension-soap.xml]
INFO ;2010-02-03
10:30:46,820;org.springframework.beans.factory.xml.XmlBeanDefinitionReader;;Loading
XML bean definitions from class path resource [META-INF/cxf/cxf-servlet.xml]
INFO ;2010-02-03
10:30:46,868;org.springframework.web.context.support.XmlWebApplicationContext;;Bean
factory for application context
[org.springframework.web.context.support.xmlwebapplicationcont...@3f56e5ed]:
org.springframework.beans.factory.support.defaultlistablebeanfact...@7d59ea8e
INFO ;2010-02-03
10:30:46,966;org.springframework.beans.factory.support.DefaultListableBeanFactory;;Pre-instantiating
singletons in
org.springframework.beans.factory.support.defaultlistablebeanfact...@7d59ea8e:
defining beans
[cxf,org.apache.cxf.bus.spring.BusApplicationListener,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,org.apache.cxf.resource.ResourceManager,org.apache.cxf.configuration.Configurer,org.apache.cxf.binding.BindingFactoryManager,org.apache.cxf.transport.DestinationFactoryManager,org.apache.cxf.transport.ConduitInitiatorManager,org.apache.cxf.wsdl.WSDLManager,org.apache.cxf.phase.PhaseManager,org.apache.cxf.workqueue.WorkQueueManager,org.apache.cxf.buslifecycle.BusLifeCycleManager,org.apache.cxf.endpoint.ServerRegistry,org.apache.cxf.endpoint.ServerLifeCycleManager,org.apache.cxf.endpoint.ClientLifeCycleManager,org.apache.cxf.transports.http.QueryHandlerRegistry,org.apache.cxf.endpoint.EndpointResolverRegistry,org.apache.cxf.headers.HeaderManager,org.apache.cxf.catalog.OASISCatalogManager,org.apache.cxf.endpoint.ServiceContractResolverRegistry,org.apache.cxf.binding.soap.SoapBindingFactory,org.apache.cxf.binding.soap.SoapTransportFactory,org.apache.cxf.binding.soap.customEditorConfigurer,org.apache.cxf.transport.servlet.ServletTransportFactory,MyService];
root of factory hierarchy
INFO ;2010-02-03
10:30:48,367;org.springframework.web.context.ContextLoader;;Root
WebApplicationContext: initialization completed in 1757 ms
INFO ;2010-02-03
10:30:48,381;org.apache.cxf.bus.spring.BusApplicationContext;;Refreshing
org.apache.cxf.bus.spring.busapplicationcont...@1259b924: display name
[org.apache.cxf.bus.spring.busapplicationcont...@1259b924]; startup date
[Wed Feb 03 10:30:48 CET 2010]; parent:
org.springframework.web.context.support.xmlwebapplicationcont...@3f56e5ed
INFO ;2010-02-03
10:30:48,390;org.apache.cxf.bus.spring.BusApplicationContext;;Bean
factory for application context
[org.apache.cxf.bus.spring.busapplicationcont...@1259b924]:
org.springframework.beans.factory.support.defaultlistablebeanfact...@15357784
INFO ;2010-02-03
10:30:48,390;org.springframework.beans.factory.support.DefaultListableBeanFactory;;Pre-instantiating
singletons in
org.springframework.beans.factory.support.defaultlistablebeanfact...@15357784:
defining beans []; parent:
org.springframework.beans.factory.support.defaultlistablebeanfact...@7d59ea8e
ERROR;2010-02-03 10:30:50,847;myservice.db.dao.CostumerHome;;Could not
locate SessionFactory in JNDI
javax.naming.NameNotFoundException: Name MyHibernateSession is not bound
in this Context
...
I searched the net but I didn't found any related, so I hope you can
help me.
Best regards Alex.
<?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:jaxws="http://cxf.apache.org/jaxws"
xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/core
http://cxf.apache.org/schemas/core.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="MyService"
implementor="myservice.service.impl.MyServicePortTypeImpl" address="/service"
wsdlLocation="WEB-INF/wsdl/MyService.wsdl">
<jaxws:properties>
<entry key="mtom-enabled" value="true" />
</jaxws:properties>
</jaxws:endpoint>
</beans>
<?xml version='1.0' encoding='utf-8'?>
<Context reloadable="true">
<Resource name="jdbc/mydb" global="jdbc/mydb" auth="Container"
type="javax.sql.DataSource" username="dba" password="sql"
driverClassName="com.sybase.jdbc3.jdbc.SybDriver" url="jdbc:sybase:Tds:localhost:2638"
maxActive="30" maxIdle="10" maxWait="4000" />
</Context>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="MyHibernateSession">
<property name="connection.datasource">java:comp/env/jdbc/mydb</property>
<property name="hibernate.dialect">org.hibernate.dialect.Sybase11Dialect</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<mapping resource="myservice/db/domain/Costumer.hbm.xml" />
</session-factory>
</hibernate-configuration>
package myservice.db.hibernate;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
public class InitSessionFactory {
private static Logger log = Logger.getLogger(InitSessionFactory.class);
/** The single instance of hibernate SessionFactory */
private static org.hibernate.SessionFactory sessionFactory;
/**
* Default constructor. It is private to guaranty singleton
*/
private InitSessionFactory() {
}
static {
final Configuration cfg = new Configuration();
cfg.configure("/hibernate.cfg.xml");
String sessionFactoryJndiName = cfg.getProperty(Environment.SESSION_FACTORY_NAME);
try {
if (sessionFactoryJndiName != null) {
cfg.buildSessionFactory();
log.debug("get a jndi session factory");
sessionFactory = (SessionFactory) (new InitialContext()).lookup(sessionFactoryJndiName);
}
else {
log.debug("classic factory");
sessionFactory = cfg.buildSessionFactory();
}
}
catch (NamingException e) {
throw new HibernateException("Could not configure Hibernate configuration", e);
}
}
/**
* Returns the single instance of the session factory
*
* @return
*/
public static SessionFactory getInstance() {
return sessionFactory;
}
}
package myservice.db.hibernate;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class ServletListener implements ServletContextListener {
/**
* initialize the factory
*/
public void contextInitialized(ServletContextEvent arg0) {
InitSessionFactory.getInstance();
}
/**
* close down sessionFactory and free ressources
*/
public void contextDestroyed(ServletContextEvent arg0) {
InitSessionFactory.getInstance().close();
}
}
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>myService</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>myservice.db.hibernate.ServletListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/mydb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>