0 Replies Latest reply on Sep 26, 2012 2:55 AM by Thirupathi Rao Veerla

    jndi look up using spring gives name not found - jboss AS 7.0.2 Final

    Thirupathi Rao Veerla Newbie

      I have created a test projects (client project - web app, a java project which has services) with a simple servlet calling service which has spring annotated transactions. When i deployed the project and try to run it, i see javax.naming.NameNotFoundException: unable to find a bound object at name 'datasources/test'. The spring is loaded using classpath xml.

       

      Servlet code to get service from spring.

      protected void doPost(HttpServletRequest req, HttpServletResponse resp)

                                    throws ServletException, IOException {

                          System.out.println("this is test servlet");

                          ApplicationContext context = BusinessApplicationContextUtil

                          .getApplicationContext();

       

                            IJbpmService service = (IJbpmService) context.getBean("jbpmService");

                          service.jbpmService();

       

                          System.out.println("end");

                }

       

      BusinessApplicationContextUtil:

       

      public class BusinessApplicationContextUtil implements ApplicationContextAware{

       

                private static ApplicationContext applicationContext;

       

       

                public static ApplicationContext getApplicationContext() {

                          if (applicationContext == null) {

                                    applicationContext = new ClassPathXmlApplicationContext("classpath*:spring-context.xml");

                          }

                          return applicationContext;

                }

       

       

                public void setApplicationContext(ApplicationContext arg0)

                                    throws BeansException {

                          applicationContext = arg0;

       

                }

      }

       

       


      Spring-context.xml (which is in service project):

       

      <?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:jee="http://www.springframework.org/schema/jee"

                xmlns:tx="http://www.springframework.org/schema/tx"

                xsi:schemaLocation="http://www.springframework.org/schema/beans  

             http://www.springframework.org/schema/beans/spring-beans-2.5.xsd

             http://www.springframework.org/schema/jee

             http://www.springframework.org/schema/jee/spring-jee-2.5.xsd

              http://www.springframework.org/schema/tx

            http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"

                default-autowire="byType">

        

       

                <bean id="creditApplicationBS" class="com.businessservice.impl.CreditApplicationBSImpl" />

                <bean id="documentBS" class="com.businessservice.impl.DocumentBSImpl" />

       

                <bean id="jbpmService" class="com.businessservice.impl.JbpmService" />

       

       

                <bean id="documentDao" class="com.dao.DocumentDAO">

                </bean>

       

       

                <bean

                          class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

       

       

      <jee:jndi-lookup jndi-name="java:jboss/datasources/test"

                          id="myDatasource" />

       

       

                <bean id="txManager"

                          class="org.springframework.transaction.jta.JtaTransactionManager">

                          <property name="transactionManagerName" value="java:jboss/TransactionManager" />

                </bean>

       

       

                <tx:annotation-driven transaction-manager="txManager" />

            

                <bean id="APMEntityManagerFactory"

                          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

                          <property name="dataSource" ref="myDatasource" />

                          <property name="persistenceUnitName" value="fiomPersistenceUnit" />

                          <property name="jpaVendorAdapter">

                                    <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">

                                              <property name="showSql" value="true" />

                                              <property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect" />

                                              <property name="generateDdl" value="false" />

                                    </bean>

                          </property>

                          <property name="jpaPropertyMap">

                                    <map>

                                              <entry key="hibernate.current_session_context_class" value="thread" />

                                              <entry key="hibernate.show_sql" value="true" />

                                    </map>

                          </property>

                </bean>

        </beans>

       

      When i test the datasource using jboss-admin.bat, i see the result as below:

       

      [standalone@localhost:9999 /] /subsystem=datasources/data-source=java\:jboss\/da

      tasources\/test:test-connection-in-pool

      {

          "outcome" => "success",

          "result" => [true]

      }

       

      Any help on this is much appreciated.

       

      Thanks in advance.