What is strange is that the bean has been instantiated by the container ?
DefaultListableBeanFactory DEBUG Creating instance of bean 'orderDAO' with merged definition [Root bean: class [com.xpectis.dao.OrderDAOHibernateImpl]; scope=singleton; abstract=false; lazyInit=false; autowireCandidate=true; autowireMode=0; dependencyCheck=0; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [D:\Soft\opensource\apache-camel-1.x\examples\camel-example-spring\eclipse-classes\META-INF\spring\camel-context.xml]] DefaultListableBeanFactory DEBUG Eagerly caching bean 'orderDAO' to allow for resolving potential circular references So why the object orderDAO is null in my class ? Charles cmoulliard wrote: > > Another error is generated during Spring initialisation : > > GRAVE: Failed: org.springframework.beans.factory.BeanCreationException: > Error creating bean with name 'camel:beanPostProcessor': Cannot resolve > reference to bean 'camel' while setting bean property 'camelContext'; > nested exception is > org.springframework.beans.factory.BeanCreationException: Error creating > bean with name 'camel': Initialization of bean failed; nested exception is > org.springframework.beans.InvalidPropertyException: Invalid property 'c' > of bean class [org.apache.camel.spring.CamelContextFactoryBean]: No > property 'c' found > org.springframework.beans.factory.BeanCreationException: Error creating > bean with name 'camel:beanPostProcessor': Cannot resolve reference to bean > 'camel' while setting bean property 'camelContext'; nested exception is > org.springframework.beans.factory.BeanCreationException: Error creating > bean with name 'camel': Initialization of bean failed; nested exception is > org.springframework.beans.InvalidPropertyException: Invalid property 'c' > of bean class [org.apache.camel.spring.CamelContextFactoryBean]: No > property 'c' found > at > org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275) > at > org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104) > at > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1172) > at > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:940) > at > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:437) > at > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:383) > at java.security.AccessController.doPrivileged(Native Method) > at > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:353) > at > org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245) > at > org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169) > at > org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242) > at > org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) > at > org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:888) > at > org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:594) > at > org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:351) > at > org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:123) > at > org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:76) > at > org.apache.camel.spring.Main.createDefaultApplicationContext(Main.java:311) > at org.apache.camel.spring.Main.doStart(Main.java:302) > at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:51) > at org.apache.camel.spring.Main.run(Main.java:104) > at org.apache.camel.spring.Main.run(Main.java:95) > at > org.apache.camel.example.spring.MyRouteBuilder.main(MyRouteBuilder.java:46) > Caused by: org.springframework.beans.factory.BeanCreationException: Error > creating bean with name 'camel': Initialization of bean failed; nested > exception is org.springframework.beans.InvalidPropertyException: Invalid > property 'c' of bean class > [org.apache.camel.spring.CamelContextFactoryBean]: No property 'c' found > at > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:445) > at > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:383) > at java.security.AccessController.doPrivileged(Native Method) > at > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:353) > at > org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245) > at > org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169) > at > org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242) > at > org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) > at > org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269) > ... 22 more > Caused by: org.springframework.beans.InvalidPropertyException: Invalid > property 'c' of bean class > [org.apache.camel.spring.CamelContextFactoryBean]: No property 'c' found > at > org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:377) > at > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1211) > at > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1177) > at > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:940) > at > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:437) > ... 30 more > > > Camelcontext : > > <?xml version="1.0" encoding="UTF-8"?> > <beans xmlns="http://www.springframework.org/schema/beans" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation=" > http://www.springframework.org/schema/beans > http://www.springframework.org/schema/beans/spring-beans-2.5.xsd > http://activemq.apache.org/camel/schema/spring > http://activemq.apache.org/camel/schema/spring/camel-spring.xsd"> > > <!-- lets configure the default ActiveMQ broker URL --> > <bean id="test-jms" > class="org.apache.camel.component.jms.JmsComponent"> > <property name="connectionFactory"> > <bean > > class="org.apache.activemq.ActiveMQConnectionFactory"> > <property name="brokerURL" > > value="vm://localhost?broker.persistent=false&broker.useJmx=false" /> > </bean> > </property> > </bean> > > <bean id="Converter" class="com.xpectis.transform.Converter" /> > > > <!-- DB connection and persistence layer --> > > <!-- DataSource Definition --> > <bean id="dataSource" > class="org.apache.commons.dbcp.BasicDataSource" > destroy-method="close"> > <property name="driverClassName"> > <value>com.mysql.jdbc.Driver</value> > </property> > <property name="url"> > <value>jdbc:mysql:///test</value> > </property> > <property name="username"> > <value>root</value> > </property> > <property name="password"> > <value></value> > </property> > </bean> > > <!-- Hibernate SessionFactory Definition --> > <bean id="sessionFactory" > > class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> > <property name="mappingResources"> > <list> > <value> > com/xpectis/model/order.hbm.xml > </value> > </list> > </property> > > <property name="hibernateProperties"> > <props> > <prop key="hibernate.dialect"> > org.hibernate.dialect.MySQLDialect > </prop> > <prop key="hibernate.show_sql">true</prop> > <prop key="hibernate.format_sql">true</prop> > <prop key="hibernate.default_schema">test</prop> > <prop > key="hibernate.cglib.use_reflection_optimizer"> > true > </prop> > <prop key="hibernate.cache.provider_class"> > > org.hibernate.cache.HashtableCacheProvider > </prop> > </props> > </property> > > <property name="dataSource"> > <ref bean="dataSource" /> > </property> > </bean> > > <!-- Hibernate Template Defintion > <bean id="hibernateTemplate" > class="org.springframework.orm.hibernate3.HibernateTemplate"> > <property name="sessionFactory"><ref > bean="sessionFactory"/></property> > <property name="jdbcExceptionTranslator"><ref > bean="jdbcExceptionTranslator"/></property> > </bean> --> > > <!-- Catalog DAO Definition: Hibernate implementation --> > <bean id="orderDAO" > class="com.xpectis.dao.OrderDAOHibernateImpl"> > <property name="sessionFactory"> > <ref bean="sessionFactory" /> > </property> > </bean> > > <!-- Hibernate Transaction Manager Definition --> > <bean id="transactionManager" > > class="org.springframework.orm.hibernate3.HibernateTransactionManager"> > <property name="sessionFactory"> > <ref local="sessionFactory" /> > </property> > </bean> > > <!-- Spring Data Access Exception Translator Defintion --> > <bean id="jdbcExceptionTranslator" > > class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator"> > <property name="dataSource"> > <ref bean="dataSource" /> > </property> > </bean> > > <c:camelContext id="camel" useJmx="false" mbeanServer="mbeanServer" > xmlns:c="http://activemq.apache.org/camel/schema/spring"> > > <c:package>org.apache.camel.example.spring</c:package> > </c:camelContext> > > </beans> > > > > > Gert Vanthienen wrote: >> >> Charles, >> >> Could you try explicitly prefixing the camel namespace to rule out any >> namespace conflicts? Something like... >> >> <c:camelContext id="camel" useJmx="false" mbeanServer="mbeanServer" >> >> xmlns:c="http://activemq.apache.org/camel/schema/spring"> >> <c:package>org.apache.camel.example.spring</c:package> >> </c:camelContext> >> >> >> >> Gert >> cmoulliard wrote: >>> Unfortunately, it does not work also, if I move the following xml part >>> to the >>> bottom of my camelcontext.xml file : >>> >>> <camelContext id="camel" useJmx="false" >>> mbeanServer="mbeanServer" >>> xmlns="http://activemq.apache.org/camel/schema/spring"> >>> >>> <package>org.apache.camel.example.spring</package> >>> </camelContext> >>> >>> The beanFactory is still null and of course my orderDAO. >>> >>> Regards, >>> >>> Charles >>> >>> >>> James.Strachan wrote: >>> >>>> Since the <camelContext> overrides the default XML namespace - moving >>>> it to the bottom of the file should fix it. >>>> >>>> On 18/03/2008, cmoulliard <[EMAIL PROTECTED]> wrote: >>>> >>>>> Here is the camel context James : >>>>> >>>>> <?xml version="1.0" encoding="UTF-8"?> >>>>> <beans xmlns="http://www.springframework.org/schema/beans" >>>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >>>>> xsi:schemaLocation=" >>>>> http://www.springframework.org/schema/beans >>>>> http://www.springframework.org/schema/beans/spring-beans-2.5.xsd >>>>> http://activemq.apache.org/camel/schema/spring >>>>> http://activemq.apache.org/camel/schema/spring/camel-spring.xsd"> >>>>> >>>>> <camelContext id="camel" useJmx="false" >>>>> mbeanServer="mbeanServer" >>>>> >>>>> xmlns="http://activemq.apache.org/camel/schema/spring"> >>>>> <package>org.apache.camel.example.spring</package> >>>>> </camelContext> >>>>> >>>>> <!-- lets configure the default ActiveMQ broker URL --> >>>>> <bean id="test-jms" >>>>> class="org.apache.camel.component.jms.JmsComponent"> >>>>> <property name="connectionFactory"> >>>>> <bean >>>>> >>>>> class="org.apache.activemq.ActiveMQConnectionFactory"> >>>>> <property name="brokerURL" >>>>> >>>>> value="vm://localhost?broker.persistent=false&broker.useJmx=false" >>>>> /> >>>>> </bean> >>>>> </property> >>>>> </bean> >>>>> >>>>> <bean id="Converter" class="com.xpectis.transform.Converter" >>>>> /> >>>>> >>>>> >>>>> <!-- DB connection and persistence layer --> >>>>> >>>>> <!-- DataSource Definition --> >>>>> <bean id="dataSource" >>>>> class="org.apache.commons.dbcp.BasicDataSource" >>>>> destroy-method="close"> >>>>> <property name="driverClassName"> >>>>> <value>com.mysql.jdbc.Driver</value> >>>>> </property> >>>>> <property name="url"> >>>>> <value>jdbc:mysql:///test</value> >>>>> </property> >>>>> <property name="username"> >>>>> <value>root</value> >>>>> </property> >>>>> <property name="password"> >>>>> <value></value> >>>>> </property> >>>>> </bean> >>>>> >>>>> <!-- Hibernate SessionFactory Definition --> >>>>> <bean id="sessionFactory" >>>>> >>>>> class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> >>>>> <property name="mappingResources"> >>>>> <list> >>>>> <value> >>>>> >>>>> com/xpectis/model/order.hbm.xml >>>>> </value> >>>>> </list> >>>>> </property> >>>>> >>>>> <property name="hibernateProperties"> >>>>> <props> >>>>> <prop key="hibernate.dialect"> >>>>> >>>>> org.hibernate.dialect.MySQLDialect >>>>> </prop> >>>>> <prop >>>>> key="hibernate.show_sql">true</prop> >>>>> <prop >>>>> key="hibernate.format_sql">true</prop> >>>>> <prop >>>>> key="hibernate.default_schema">test</prop> >>>>> <prop >>>>> key="hibernate.cglib.use_reflection_optimizer"> >>>>> true >>>>> </prop> >>>>> <prop >>>>> key="hibernate.cache.provider_class"> >>>>> >>>>> org.hibernate.cache.HashtableCacheProvider >>>>> </prop> >>>>> </props> >>>>> </property> >>>>> >>>>> <property name="dataSource"> >>>>> <ref bean="dataSource" /> >>>>> </property> >>>>> </bean> >>>>> >>>>> <!-- Hibernate Template Defintion >>>>> <bean id="hibernateTemplate" >>>>> class="org.springframework.orm.hibernate3.HibernateTemplate"> >>>>> >>>>> <property name="sessionFactory"><ref >>>>> bean="sessionFactory"/></property> >>>>> >>>>> <property name="jdbcExceptionTranslator"><ref >>>>> bean="jdbcExceptionTranslator"/></property> >>>>> </bean> --> >>>>> >>>>> >>>>> <!-- Catalog DAO Definition: Hibernate implementation --> >>>>> <bean id="orderDAO" >>>>> class="com.xpectis.dao.OrderDAOHibernateImpl"> >>>>> <property name="sessionFactory"> >>>>> <ref bean="sessionFactory" /> >>>>> </property> >>>>> </bean> >>>>> >>>>> >>>>> <!-- Hibernate Transaction Manager Definition --> >>>>> <bean id="transactionManager" >>>>> >>>>> class="org.springframework.orm.hibernate3.HibernateTransactionManager"> >>>>> <property name="sessionFactory"> >>>>> <ref local="sessionFactory" /> >>>>> </property> >>>>> </bean> >>>>> >>>>> <!-- Spring Data Access Exception Translator Defintion --> >>>>> <bean id="jdbcExceptionTranslator" >>>>> >>>>> >>>>> class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator"> >>>>> <property name="dataSource"> >>>>> <ref bean="dataSource" /> >>>>> </property> >>>>> </bean> >>>>> >>>>> <!-- >>>>> <bean id="Order" class="com.xpectis.model.Order" /> >>>>> <bean id="registry" >>>>> class="org.springframework.remoting.rmi.RmiRegistryFactoryBean"> >>>>> <property name="port" value="1099" /> >>>>> </bean> >>>>> <bean id="serverConnector" >>>>> class="org.springframework.jmx.support.ConnectorServerFactoryBean" >>>>> depends-on="registry"> >>>>> <property name="objectName" value="connector:name=rmi" >>>>> /> >>>>> <property name="serviceUrl" >>>>> value="service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi" /> >>>>> <property name="threaded" value="true" /> >>>>> <property name="daemon" value="true" /> >>>>> </bean> >>>>> --> >>>>> >>>>> </beans> >>>>> >>>>> >>>>> >>>>> >>>>> James.Strachan wrote: >>>>> > >>>>> > Any chance you could show us the whole spring XML file? Am >>>>> wondering >>>>> > if its something to do with namespaces? >>>>> > >>>>> > On 18/03/2008, cmoulliard <[EMAIL PROTECTED]> wrote: >>>>> >> >>>>> >> Hi, >>>>> >> >>>>> >> I try from one of my java class to inject an >>>>> HibernateDAOImplementation >>>>> >> defined as a bean in the CamelContext file. Unfortunately, I >>>>> receive >>>>> a >>>>> >> null >>>>> >> pointer exception at the following line : >>>>> >> >>>>> >> orderDAO = >>>>> (OrderDAOHibernateImpl)this.beanFactory.getBean("orderDAO"); >>>>> >> >>>>> >> the beanFactory object is null >>>>> >> >>>>> >> import org.springframework.beans.BeansException; >>>>> >> import org.springframework.beans.factory.BeanFactory; >>>>> >> import org.springframework.beans.factory.BeanFactoryAware; >>>>> >> import org.springframework.dao.DataIntegrityViolationException; >>>>> >> >>>>> >> import com.xpectis.dao.OrderDAO; >>>>> >> import com.xpectis.dao.OrderDAOHibernateImpl; >>>>> >> import com.xpectis.model.Order; >>>>> >> >>>>> >> public class SaveOrder implements BeanFactoryAware { >>>>> >> >>>>> >> private BeanFactory beanFactory; >>>>> >> private OrderDAO orderDAO; >>>>> >> >>>>> >> public SaveOrder() { >>>>> >> } >>>>> >> >>>>> >> public void save(Order order) { >>>>> >> >>>>> >> >>>>> >> orderDAO = >>>>> >> (OrderDAOHibernateImpl)this.beanFactory.getBean("orderDAO"); >>>>> >> >>>>> >> try { >>>>> >> this.orderDAO.addOrder(order); >>>>> >> System.out.println("Order saved : " + >>>>> >> order.toString()); >>>>> >> } catch (DataIntegrityViolationException de) { >>>>> >> System.out.println("Could not save >>>>> product, >>>>> >> duplicate product id"); >>>>> >> } catch (Exception e) { >>>>> >> System.out.println("Could not save product >>>>> " >>>>> + >>>>> >> e.toString()); >>>>> >> } >>>>> >> } >>>>> >> >>>>> >> public void setBeanFactory(BeanFactory beanFactory) { >>>>> >> this.beanFactory = beanFactory; >>>>> >> } >>>>> >> >>>>> >> public OrderDAO getOrderDAO() { >>>>> >> return orderDAO; >>>>> >> } >>>>> >> >>>>> >> public void setOrderDAO(OrderDAO orderDAO) { >>>>> >> this.orderDAO = orderDAO; >>>>> >> } >>>>> >> >>>>> >> } >>>>> >> >>>>> >> Here is the camelcontext file where my bean is declared. >>>>> >> >>>>> >> <!-- Catalog DAO Definition: Hibernate implementation --> >>>>> >> <bean id="orderDAO" >>>>> >> class="com.xpectis.dao.OrderDAOHibernateImpl"> >>>>> >> <property name="sessionFactory"> >>>>> >> <ref bean="sessionFactory" /> >>>>> >> </property> >>>>> >> </bean> >>>>> >> >>>>> >> >>>>> >> When this code runs in Spring context, it works. So, where is the >>>>> issue >>>>> >> with >>>>> >> Camel ?? >>>>> >> >>>>> >> Regards, >>>>> >> >>>>> >> Charles >>>>> >> >>>>> >> >>>>> >> -- >>>>> >> View this message in context: >>>>> >> >>>>> http://www.nabble.com/BeanFactoryAware-%28Spring%29-tp16122107s22882p16122107.html >>>>> >> Sent from the Camel - Users mailing list archive at Nabble.com. >>>>> >> >>>>> >> >>>>> > >>>>> > >>>>> > -- >>>>> > James >>>>> > ------- >>>>> > http://macstrac.blogspot.com/ >>>>> > >>>>> > Open Source Integration >>>>> > http://open.iona.com >>>>> > >>>>> > >>>>> >>>>> >>>>> -- >>>>> View this message in context: >>>>> http://www.nabble.com/BeanFactoryAware-%28Spring%29-tp16122107s22882p16124218.html >>>>> >>>>> Sent from the Camel - Users mailing list archive at Nabble.com. >>>>> >>>>> >>>>> >>>> -- >>>> James >>>> ------- >>>> http://macstrac.blogspot.com/ >>>> >>>> Open Source Integration >>>> http://open.iona.com >>>> >>>> >>>> >>> >>> >> >> >> >> ----- >> --- >> Gert Vanthienen >> http://www.anova.be >> > > -- View this message in context: http://www.nabble.com/BeanFactoryAware-%28Spring%29-tp16122107s22882p16144399.html Sent from the Camel - Users mailing list archive at Nabble.com.
