L.S.,

Another way of solving this would be using the JNDI integration to get
at the bean.  All the beans in the jndiEntries map can be accessed by
doing a JNDI lookup without requiring the import of the entire
jndi.xml file.

E.g. if you add a JPA EntityManager bean in this map under key
java:/comp/env/EntityManager, you can access it from your SU by doing
a JNDI lookup like
  <bean id="entityManager"
class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:/comp/env/EntityManager"/>
  </bean>

Regards,

Gert Vanthienen
------------------------
Open Source SOA: http://fusesource.com
Blog: http://gertvanthienen.blogspot.com/



2009/11/30 S_BN <[email protected]>:
>
>
> Resolved!
> Solution is to import the jndi.xml inside the xbean of the SU
> <import resource="classpath*:jndi.xml"/>
>
> my xbean now looks like
>
> <?xml version="1.0"?>
> <beans xmlns:cxfse="http://servicemix.apache.org/cxfse/1.0";
>       xmlns:sm="http://servicemix.apache.org/config/1.0";
>       xmlns:b="http://servicemix.apache.org/samples/bridge";
>           xmlns:util="http://www.springframework.org/schema/util";>
>
>
> <import resource="classpath*:jndi.xml"/>
>  <cxfse:endpoint service="b:testcxfse"
>                 endpoint="endpoint">
>
>
>   <cxfse:pojo>
>     <bean class="com.nsn.oss.nat.lct.mediation.snmp_udp.advise.AdviseImpl">
>       <property name="localIp">
>          <value>10.254.126.23</value>
>        </property>
>                 <property name="localPort">
>          <value>1612</value>
>        </property>
>                 <property name="neDataAccess" ref="neDataAccessDao"/>
>     </bean>
>  </cxfse:pojo>
> </cxfse:endpoint>
>
> ======================================
>
>
> S_BN wrote:
>>
>> Hello,
>>
>> I am using JPA/Hibernate in servicemix.
>> Here is my usecase:
>> I have created a jar for the database helper using JPA/Hibernate. I have
>> put this in servicemix\lib
>> I have created a SA containing SU which will need to access methods from
>> dbHelper.jar
>>
>> I have added the following to the jndi.xml under servicemix\conf
>> <util:map id="jndiEntries">
>>               <entry key="JPAEntityManager" value-ref="entityManagerFactory" 
>> />
>> .
>> .
>> </util:map>
>>
>> <bean id="entityManagerFactory"
>>
>> class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
>>               <property name="persistenceUnitManager" 
>> ref="persistenceUnitManager" />
>>               <property name="dataSource" ref="dataSource" />
>>               <property name="jpaVendorAdapter">
>>                       <bean
>> class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
>>                               <property name="showSql" value="true" />
>>                               <property name="generateDdl" value="false" />
>>                               <property name="databasePlatform"
>> value="org.hibernate.dialect.HSQLDialect" />
>>                               <!--property name="databasePlatform"
>> value="org.hibernate.dialect.Oracle9Dialect" /-->
>>                       </bean>
>>               </property>
>>               <property name="loadTimeWeaver">
>>                       <bean
>> class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver"/>
>>               </property>
>>       </bean>
>>
>>       <bean id="JPAtransactionManager"
>> class="org.springframework.orm.jpa.JpaTransactionManager">
>>               <property name="dataSource" ref="dataSource" />
>>               <property name="entityManagerFactory" 
>> ref="entityManagerFactory" />
>>       </bean>
>>
>>
>>       <bean
>> class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"
>> />
>>       <bean
>> class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"
>> />
>>
>>       <bean id="dataSource_oracle"
>> class="org.springframework.jdbc.datasource.DriverManagerDataSource">
>>               <property name="driverClassName" 
>> value="oracle.jdbc.driver.OracleDriver"
>> />
>>               <property name="url" 
>> value="jdbc:oracle:thin:@10.58.116.101:1521:OSS" />
>>               <property name="username" value="omc" />
>>               <property name="password" value="omc" />
>>       </bean>
>>
>>       <bean id="dataSource"
>> class="org.springframework.jdbc.datasource.DriverManagerDataSource">
>>               <property name="driverClassName" value="org.hsqldb.jdbcDriver" 
>> />
>>               <property name="url" value="jdbc:hsqldb:." />
>>               <property name="username" value="sa" />
>>               <property name="password" value="" />
>>       </bean>
>>
>>       <bean id="persistenceUnitManager"
>>
>> class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
>>               <property name="persistenceXmlLocations">
>>                       <list>
>>                               
>> <value>classpath*:lctMediation-dataAccess-persistence.xml</value>
>>                       </list>
>>               </property>
>>               <property name="defaultDataSource" ref="dataSource" />
>>
>>       </bean>
>>
>> Here is the xbean i have used for the SU
>> <?xml version="1.0"?>
>> <beans xmlns:cxfse="http://servicemix.apache.org/cxfse/1.0";
>>        xmlns:sm="http://servicemix.apache.org/config/1.0";
>>        xmlns:b="http://servicemix.apache.org/samples/bridge";>
>>
>>   <cxfse:endpoint service="b:testcxfse"
>>                  endpoint="endpoint">
>>
>>
>>    <cxfse:pojo>
>>      <bean
>> class="com.nsn.oss.nat.lct.mediation.snmp_udp.advise.AdviseImpl">
>>        <property name="localIp">
>>           <value>10.254.126.23</value>
>>         </property>
>>                <property name="localPort">
>>           <value>1612</value>
>>         </property>
>>                <property name="neDataAccess" ref="neDataAccessDao"/>
>>
>>      </bean>
>>  </cxfse:pojo>
>>
>> </cxfse:endpoint>
>>
>> When I deploy the SU, i get the following exception
>> (The same error does not occur if i remove bean definitions from jndi.xml
>> and put it inside the xbean.xml itself!!!. But, I will have multiple SUs
>> in different SA which need to use the same dbHelper.
>> So I would prefer to have JPA/HIbernate dependency injection from jndi.xml
>> rather than in xbean.xml of SU)
>>
>> Exception:
>> DEBUG - CxfSeComponent                 - Looking for
>> D:\NetActTransport1.0\Tools\apache-servicemix-3.3.1\data\smx\service-assemblies\nat-common-cxf-sa\version_1\sus\servicemix-cxf-se\nat-common-cxf-se-su\xbean.xml:
>> true
>> ERROR - CxfSeComponent                 -
>> org.springframework.beans.factory.BeanCreationException: Error creating
>> bean with name 'org.apache.servicemix.cxfse.CxfSeEndpoint#0' defined in
>> file
>> [D:\NetActTransport1.0\Tools\apache-servicemix-3.3.1\data\smx\service-assemblies\nat-common-cxf-sa\version_1\sus\servicemix-cxf-se\nat-common-cxf-se-su\xbean.xml]:
>> Cannot create inner bean
>> 'com.nsn.oss.nat.lct.mediation.snmp_udp.advise.AdviseImpl#0' of type
>> [com.nsn.oss.nat.lct.mediation.snmp_udp.advise.AdviseImpl] while setting
>> bean property 'pojo'; nested exception is
>> org.springframework.beans.factory.BeanCreationException: Error creating
>> bean with name
>> 'com.nsn.oss.nat.lct.mediation.snmp_udp.advise.AdviseImpl#0' defined in
>> file
>> [D:\NetActTransport1.0\Tools\apache-servicemix-3.3.1\data\smx\service-assemblies\nat-common-cxf-sa\version_1\sus\servicemix-cxf-se\nat-common-cxf-se-su\xbean.xml]:
>> Cannot resolve reference to bean 'neDataAccessDao' while setting bean
>> property 'neDataAccess'; nested exception is
>> org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean
>> named 'neDataAccessDao' is defined
>>
>>
>> I do not understand why SU's xbean.xml is unable to refer to the bean
>> created in jndi.xml of servicemix\conf
>>
>> Is there any other configuration to be done?
>>
>> Thanks in advance.
>> Best Regards,
>> Sindhu
>>
>>
>
> --
> View this message in context: 
> http://old.nabble.com/xbean.xml-Cannot-create-inner-bean-%28defined-in-jndi.xml%29-tp26535002p26570012.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>

Reply via email to