CannotLoadBeanClassException: Hibernate in a Equinox Bundle
I am developing an application on Equinox. I an a Web Client that calls a jar server service. This jar integrates Spring and Hibernate. My spring config file is:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://localhost:5432/3encult" />
<property name="password" value="3encult" />
<property name="username" value="3encult" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="mappingResources">
<list>
<value>
User.hbm.xml
</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<!-- Especificamos el valor minimo del pool de conexiones -->
<prop key="hibernate.c3p0.minPoolSize">5</prop>
<!-- Especificamos el valor maximo del pool de conexiones -->
<prop key="hibernate.c3p0.maxPoolSize">20</prop>
<!-- El tiempo de vida de cada conexion del pool. -->
<prop key="hibernate.c3p0.timeout">600</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="myUserDAO" class="service.User">
<property name="sessionFactory" r开发者_StackOverflow社区ef="sessionFactory" />
</bean>
</beans>
From my class I write:
ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"service/service-dao.xml"});
private SessionFactory sessionFactory = (SessionFactory)context.getBean("sessionFactory");
And the manifest imports the needed packages to Spring and Hibernate, like this:
Require-Bundle: jdbc+hibernate
Import-Package: org.springframework.orm.hibernate3, org.apache.commons.dbcp,
org.springframework.beans.factory.annotation,
org.springframework.beans.factory.xml,
org.springframework.context,
org.springframework.core.io,
org.springframework.context.support
However, I get an exception which says the bundle doesn't find the class. But the package org.springframework.orm.hibernate3 is imported in the manifest.
org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.springframework.orm.hibernate3.LocalSessionFactoryBean] for bean with name 'sessionFactory' defined in class path resource [service/service-dao.xml]: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org.springframework.orm.hibernate3.LocalSessionFactoryBean not found from bundle [ZBGWTApp (ZBGWTApp;singleton:=true)]
Also, the bundles are ACTIVE and, of course, they export the packages:
55 ACTIVE org.springframework.transaction_2.5.6
56 ACTIVE org.springframework.orm_2.5.6
57 ACTIVE org.springframework.jdbc_2.5.6
58 ACTIVE org.apache.commons.pool_1.5.6
59 ACTIVE org.apache.commons.dbcp_1.4.0
I don't know what is the reason, if all seems right.
The complete stacktrace is:
2011-06-07 07:36:59.570:WARN:/:Exception while dispatching incoming RPC call
com.google.gwt.user.client.rpc.SerializationException: Type 'org.springframework.beans.factory.CannotLoadBeanClassException' was not assignable to 'com.google.gwt.user.client.rpc.IsSerializable' and did not have a custom field serializer.For security purposes, this type will not be serialized.: instance = org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.springframework.orm.hibernate3.LocalSessionFactoryBean] for bean with name 'sessionFactory' defined in class path resource [service/service-dao.xml]: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org.springframework.orm.hibernate3.LocalSessionFactoryBean not found from bundle [ZBGWTApp (ZBGWTApp;singleton:=true)]
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerialationStreamWriter.java:615)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractializationStreamWriter.java:126)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter$ValueWriter$8.write(ServerSerializationStreamWriter.java:153)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeValue(ServerSerializationStreamWriter.java:535)
at com.google.gwt.user.server.rpc.RPC.encodeResponse(RPC.java:616)
at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:390)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:588)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at main.java.com.gwt.app.server.GreetingServiceImpl.service(GreetingServiceImpl.java:30)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.eclipse.equinox.http.registry.internal.ServletManager$ServletWrapper.service(ServletManager.java:180)
at org.eclipse.equinox.http.servlet.internal.ServletRegistration.service(ServletRegistration.java:61)
at org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:126)
at org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:60)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.eclipse.equinox.http.jetty.internal.HttpServerManager$InternalHttpServiceServlet.service(HttpServerManager.java:318)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:939)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Thanks in advance!
Regards!
精彩评论