G
Gast2
Gast
Hallo zusammen,
ich habe als ich angefangen hab mich mit Spring zu beschäftigen die Spring Framework Bundles ganz normal als jar dem ClassPath hinzugefügt. Jetzt wollte ich diese aber richtig als Bundles mit Spring DM zusammen nutzen und einbinden. Das versuche ich grad umzustellen.
Also Spring DM alleine mit ein paar Servicen funktionierte ganz gut.
Und davor hatte ich eine kleine Anwendung die eine DB connection mit Spring/Hibernate macht(ohne App Server !!!), das hat auch ganz gut geklappt. Doch jetzt die beiden Sachen zu kombinieren scheitert kläglich. Ich weiß nicht genau wo der Fehler liegt, darum kann sein dass ich eventuell zuviel Info poste:
Also ich habe meine app.xml in mein Bundle Meta-Inf/spring gelegt damit, der der Spring extender das einliest. Das klappt. Danach habe ich die benötigten package in mein Bundle importiert.
org.springframework.beans.factory.annotation,
org.springframework.context,
org.springframework.jdbc.support,
org.springframework.orm.hibernate3,
org.springframework.transaction.annotation
Die XML, die mit dem Spring Framework funktioniert hat, doch jetzt mit Spring DM nicht mehr richtig geht!
[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
sgi="http://www.springframework.org/schema/osgi"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
Index of /schema/context http://www.springframework.org/schema/context/spring-context.xsd
Index of /schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd
Index of /schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:annotation-config />
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<context
roperty-placeholder location="classpath:jdbc.properties" />
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<!-- the DataSource (parameterized for configuration via a PropertyPlaceHolderConfigurer) -->
<bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!-- Hibernate -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />
<property name="configLocation" value="hibernate.cfg.xml" />
<property name="dataSource" ref="dataSource" />
</bean>
<!-- Hibernate DAO -->
<bean id="kundenDAO" class="dao.impl.HibernateKundenDAOImpl" />
[/XML]
Die jdbc.properties und die hibernate.cfg.xml liegen immer noch im src Folder. Und die hibernate jar hab ich auch nicht verändert und sind immer noch dem classpath hinzugefügt.
Hier mal die Exception:
Also ich sehe dass er meine xml liest und versucht die beans zu laden. Und ich denke mal es scheitert an der DB verbindung. Was mit total schleierhaft ist, dass er die Hibernate Klassen nicht findet, weil die jars liegen im classpath. Oder muss ich diese jetzt mit Spring DM anders einbinden? Weil sobald die Sache mit der Datenbank, das mit der sessionFactory draußen lasse bekomme ich keinen Fehler mehr
Danke für jeden Ratschlag!
ich habe als ich angefangen hab mich mit Spring zu beschäftigen die Spring Framework Bundles ganz normal als jar dem ClassPath hinzugefügt. Jetzt wollte ich diese aber richtig als Bundles mit Spring DM zusammen nutzen und einbinden. Das versuche ich grad umzustellen.
Also Spring DM alleine mit ein paar Servicen funktionierte ganz gut.
Und davor hatte ich eine kleine Anwendung die eine DB connection mit Spring/Hibernate macht(ohne App Server !!!), das hat auch ganz gut geklappt. Doch jetzt die beiden Sachen zu kombinieren scheitert kläglich. Ich weiß nicht genau wo der Fehler liegt, darum kann sein dass ich eventuell zuviel Info poste:
Also ich habe meine app.xml in mein Bundle Meta-Inf/spring gelegt damit, der der Spring extender das einliest. Das klappt. Danach habe ich die benötigten package in mein Bundle importiert.
org.springframework.beans.factory.annotation,
org.springframework.context,
org.springframework.jdbc.support,
org.springframework.orm.hibernate3,
org.springframework.transaction.annotation
Die XML, die mit dem Spring Framework funktioniert hat, doch jetzt mit Spring DM nicht mehr richtig geht!
[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
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
Index of /schema/context http://www.springframework.org/schema/context/spring-context.xsd
Index of /schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd
Index of /schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:annotation-config />
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<context
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<!-- the DataSource (parameterized for configuration via a PropertyPlaceHolderConfigurer) -->
<bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!-- Hibernate -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />
<property name="configLocation" value="hibernate.cfg.xml" />
<property name="dataSource" ref="dataSource" />
</bean>
<!-- Hibernate DAO -->
<bean id="kundenDAO" class="dao.impl.HibernateKundenDAOImpl" />
[/XML]
Die jdbc.properties und die hibernate.cfg.xml liegen immer noch im src Folder. Und die hibernate jar hab ich auch nicht verändert und sind immer noch dem classpath hinzugefügt.
Hier mal die Exception:
Java:
Feb 15, 2010 10:50:16 PM org.springframework.osgi.extender.internal.activator.ContextLoaderListener start
INFO: Starting [org.springframework.osgi.extender] bundle v.[1.2.1]
Feb 15, 2010 10:50:16 PM org.springframework.osgi.extender.internal.support.ExtenderConfiguration <init>
INFO: No custom extender configuration detected; using defaults...
Feb 15, 2010 10:50:16 PM org.springframework.scheduling.timer.TimerTaskExecutor afterPropertiesSet
INFO: Initializing Timer
Feb 15, 2010 10:50:16 PM org.springframework.osgi.extender.support.DefaultOsgiApplicationContextCreator createApplicationContext
INFO: Discovered configurations {osgibundle:/META-INF/spring/*.xml} in bundle [RCPTest (RCPTest;singleton:=true)]
Feb 15, 2010 10:50:17 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing OsgiBundleXmlApplicationContext(bundle=RCPTest, config=osgibundle:/META-INF/spring/*.xml): startup date [Mon Feb 15 22:50:17 CET 2010]; root of context hierarchy
Feb 15, 2010 10:50:17 PM org.springframework.osgi.context.support.AbstractOsgiBundleApplicationContext unpublishContextAsOsgiService
INFO: Application Context service already unpublished
Feb 15, 2010 10:50:17 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from URL [bundleentry://4213.fwk27189676/META-INF/spring/client-context.xml]
Feb 15, 2010 10:50:18 PM org.springframework.core.io.support.PropertiesLoaderSupport loadProperties
INFO: Loading properties file from OSGi resource[classpath:jdbc.properties|bnd.id=4213|bnd.sym=RCPTest]
Feb 15, 2010 10:50:19 PM org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor stageOne
INFO: No outstanding OSGi service dependencies, completing initialization for OsgiBundleXmlApplicationContext(bundle=RCPTest, config=osgibundle:/META-INF/spring/*.xml)
Feb 15, 2010 10:50:19 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@15cd9c0: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,transactionManager,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0,dataSource,sessionFactory,angebotModel,kundenModel,mitarbeiterModel,terminModel,angebotController,kundenController,mitarbeiterController,terminController,kundenDAO,connection,angebotDAO,propertyDAO,terminDAO,mitarbeiterDAO,kundenService,angebotService,connectionService,propertyService,terminService,mitarbeiterService,GrantView,PropertiesView,ViewAngebotSearch,ViewKundenSearch,ViewMitarbeiterSearch,AngebotEditor,KundenEditor,KundenTerminEditor,MitarbeiterEditor,MultiKundenEditor,DBObjectFactory,property]; root of factory hierarchy
Feb 15, 2010 10:50:19 PM org.springframework.osgi.extender.internal.support.DefaultOsgiBundleApplicationContextListener onOsgiApplicationEvent
SEVERE: Application context refresh failed (OsgiBundleXmlApplicationContext(bundle=RCPTest, config=osgibundle:/META-INF/spring/*.xml))
java.lang.NoClassDefFoundError: org/hibernate/HibernateException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getDeclaredConstructors(Unknown Source)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:225)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:909)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:882)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:479)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:557)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:842)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355)
at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)
at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.hibernate.HibernateException
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:494)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:398)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:105)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 20 more
Exception in thread "SpringOsgiExtenderThread-2" java.lang.NoClassDefFoundError: org/hibernate/HibernateException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getDeclaredConstructors(Unknown Source)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:225)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:909)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:882)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:479)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:557)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:842)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355)
at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)
at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.hibernate.HibernateException
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:494)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:398)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:105)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 20 more
Feb 15, 2010 10:53:14 PM org.springframework.osgi.extender.internal.activator.ContextLoaderListener shutdown
INFO: Stopping [org.springframework.osgi.extender] bundle v.[1.2.1]
Feb 15, 2010 10:53:14 PM org.springframework.osgi.context.support.AbstractOsgiBundleApplicationContext unpublishContextAsOsgiService
INFO: Application Context service already unpublished
Feb 15, 2010 10:53:14 PM org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing OsgiBundleXmlApplicationContext(bundle=RCPTest, config=osgibundle:/META-INF/spring/*.xml): startup date [Mon Feb 15 22:50:17 CET 2010]; root of context hierarchy
Feb 15, 2010 10:53:14 PM org.springframework.osgi.extender.internal.support.DefaultOsgiBundleApplicationContextListener onOsgiApplicationEvent
SEVERE: Application context close failed (OsgiBundleXmlApplicationContext(bundle=RCPTest, config=osgibundle:/META-INF/spring/*.xml))
java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: OsgiBundleXmlApplicationContext(bundle=RCPTest, config=osgibundle:/META-INF/spring/*.xml): startup date [Mon Feb 15 22:50:17 CET 2010]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:320)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:950)
at org.springframework.osgi.context.support.AbstractOsgiBundleApplicationContext.doClose(AbstractOsgiBundleApplicationContext.java:197)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$501(AbstractDelegatedExecutionApplicationContext.java:69)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$2.run(AbstractDelegatedExecutionApplicationContext.java:214)
at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.normalClose(AbstractDelegatedExecutionApplicationContext.java:210)
at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.close(DependencyWaiterApplicationContextExecutor.java:374)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.doClose(AbstractDelegatedExecutionApplicationContext.java:236)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:917)
at org.springframework.osgi.extender.internal.activator.ContextLoaderListener$1.run(ContextLoaderListener.java:522)
at org.springframework.osgi.extender.internal.util.concurrent.RunnableTimedExecution$MonitoredRunnable.run(RunnableTimedExecution.java:60)
at org.springframework.scheduling.timer.DelegatingTimerTask.run(DelegatingTimerTask.java:70)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)
Feb 15, 2010 10:53:14 PM org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor close
SEVERE: Could not succesfully close context OsgiBundleXmlApplicationContext(bundle=RCPTest, config=osgibundle:/META-INF/spring/*.xml): startup date [Mon Feb 15 22:50:17 CET 2010]; root of context hierarchy
java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: OsgiBundleXmlApplicationContext(bundle=RCPTest, config=osgibundle:/META-INF/spring/*.xml): startup date [Mon Feb 15 22:50:17 CET 2010]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:320)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:950)
at org.springframework.osgi.context.support.AbstractOsgiBundleApplicationContext.doClose(AbstractOsgiBundleApplicationContext.java:197)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$501(AbstractDelegatedExecutionApplicationContext.java:69)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$2.run(AbstractDelegatedExecutionApplicationContext.java:214)
at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.normalClose(AbstractDelegatedExecutionApplicationContext.java:210)
at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.close(DependencyWaiterApplicationContextExecutor.java:374)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.doClose(AbstractDelegatedExecutionApplicationContext.java:236)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:917)
at org.springframework.osgi.extender.internal.activator.ContextLoaderListener$1.run(ContextLoaderListener.java:522)
at org.springframework.osgi.extender.internal.util.concurrent.RunnableTimedExecution$MonitoredRunnable.run(RunnableTimedExecution.java:60)
at org.springframework.scheduling.timer.DelegatingTimerTask.run(DelegatingTimerTask.java:70)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)
Feb 15, 2010 10:53:14 PM org.springframework.scheduling.timer.TimerTaskExecutor destroy
INFO: Cancelling Timer
Also ich sehe dass er meine xml liest und versucht die beans zu laden. Und ich denke mal es scheitert an der DB verbindung. Was mit total schleierhaft ist, dass er die Hibernate Klassen nicht findet, weil die jars liegen im classpath. Oder muss ich diese jetzt mit Spring DM anders einbinden? Weil sobald die Sache mit der Datenbank, das mit der sessionFactory draußen lasse bekomme ich keinen Fehler mehr
Danke für jeden Ratschlag!
Zuletzt bearbeitet von einem Moderator: