Announcement Announcement Module
Collapse
No announcement yet.
spring JNDI datasource tomcat Problem please help me. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring JNDI datasource tomcat Problem please help me.

    Hi Thanks

    In tomcat/conf/context.xml contains the resource,please see below from tomcat/conf/context.xml

    <Resource name="jdbc/ISM_rep_user"
    auth="Container"
    type="javax.sql.DataSource"
    removeAbandoned="true"
    removeAbandonedTimeout="60"
    logAbandoned="true"
    maxActive="10"
    maxIdle="5"
    maxWait="15000"
    username="ism_cust2"
    password="iamse2_"
    driverClassName="oracle.jdbc.OracleDriver" url="jdbcracle:thin:@xxx.gggg/>

    I want to read above Tomcat datasource via JNDI in my Spring configuration i am using oracle toplink
    in spring applicationContext.xml i am using like below

    <bean id="UserDatabase" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName" value="java:comp/env/jdbc/ISM_rep_user"></property>
    <property name="lookupOn" value="true"></property>
    <property name="cache" value="true"></property>
    <property name="proxyInterface" value="javax.sql.DataSource"></property>
    </bean>

    and in web.xml i am using

    <resource-ref>
    <description>Connection Pool</description>
    <res-ref-name>jdbc/ISM_rep_user</res-ref-name>
    <res-type>javax.sql.Datasource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>

    I am still getting problem please give me some example
    I am getting below error

    [INFO] [talledLocalContainer] Caused by: java.lang.IllegalStateException: ClassL
    oader [org.apache.catalina.loader.WebappClassLoader] does NOT provide an 'addTra
    nsformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start
    your Java virtual machine with Spring's agent: -javaagent:spring-agent.jar
    [INFO] [talledLocalContainer] at org.springframework.context.weaving.DefaultCo
    ntextLoadTimeWeaver.setBeanClassLoader(DefaultCont extLoadTimeWeaver.java:82)
    [INFO] [talledLocalContainer] at org.springframework.beans.factory.support.Abs
    tractAutowireCapableBeanFactory.initializeBean(Abs tractAutowireCapableBeanFactor
    y.java:1322)
    Last edited by aleddullas; Sep 5th, 2011, 01:57 AM.

  • #2
    Please use [ code][/code ] tags when posting code/xml/stacktraces that way they remain readable ...

    The stack trace has nothing to do with datasources or jndi lookups. You are using a load time weaver but aren't using an appropriate class loader, I suggest reading the reference guide on how to configure/enable that.

    Comment


    • #3
      I am suing below bean for load time weaver in applicationContext.xml is that correct i am using please suggest me
      Code:
        <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
            <property name="dataSource" ref="dataSource"/>      
            <property name="loadTimeWeaver">
                  <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
            </property> 
      	  <property name="jpaVendorAdapter">
                <bean class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter">
                  <property name="showSql" value="false"/>                
          		<property name="databasePlatform" value="oracle.toplink.essentials.platform.database.oracle.OraclePlatform"/>
                </bean>
            </property>
          </bean>
      Last edited by aleddullas; Sep 5th, 2011, 05:49 AM.

      Comment


      • #4
        As I stated the reference guide explains how to configure load time weaving for different environments. You need to configure tomcat to use a different class loader

        Comment


        • #5
          Hi thanks,

          in my application i am not using Aspect and aop, i am using JPA and toplink

          Please find the below error message i am getting now

          Code:
          ke(DelegatingMethodAccessorImpl.java:25)
          [INFO] [talledLocalContainer]   at java.lang.reflect.Method.invoke(Method.java:5
          97)
          [INFO] [talledLocalContainer]   at org.apache.catalina.startup.Bootstrap.start(B
          ootstrap.java:288)
          [INFO] [talledLocalContainer]   at org.apache.catalina.startup.Bootstrap.main(Bo
          otstrap.java:413)
          [INFO] [talledLocalContainer] Caused by: org.springframework.beans.factory.BeanC
          reationException: Error creating bean with name 'loadTimeWeaver': Initialization
           of bean failed; nested exception is java.lang.IllegalStateException: ClassLoade
          r [org.apache.catalina.loader.WebappClassLoader] does NOT provide an 'addTransfo
          rmer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start you
          r Java virtual machine with Spring's agent: -javaagent:spring-agent.jar
          [INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.Abs
          tractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.
          java:480)
          [INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.Abs
          tractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:40
          9)
          [INFO] [talledLocalContainer]   at java.security.AccessController.doPrivileged(N
          ative Method)
          [INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.Abs
          tractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.ja
          va:380)
          [INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.Abs
          tractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
          [INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.Def
          aultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
          [INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.Abs
          tractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
          [INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.Abs
          tractBeanFactory.getBean(AbstractBeanFactory.java:185)
          [INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.Abs
          tractBeanFactory.getBean(AbstractBeanFactory.java:168)
          [INFO] [talledLocalContainer]   at org.springframework.context.weaving.LoadTimeW
          eaverAwareProcessor.postProcessBeforeInitialization(LoadTimeWeaverAwareProcessor
          .java:85)
          [INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.Abs
          tractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(Abst
          ractAutowireCapableBeanFactory.java:350)
          [INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.Abs
          tractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactor
          y.java:1331)
          [INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.Abs
          tractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.
          java:473)
          [INFO] [talledLocalContainer]   ... 38 more
          [INFO] [talledLocalContainer] Caused by: java.lang.IllegalStateException: ClassL
          oader [org.apache.catalina.loader.WebappClassLoader] does NOT provide an 'addTra
          nsformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start
           your Java virtual machine with Spring's agent: -javaagent:spring-agent.jar
          [INFO] [talledLocalContainer]   at org.springframework.context.weaving.DefaultCo
          ntextLoadTimeWeaver.setBeanClassLoader(DefaultContextLoadTimeWeaver.java:82)
          [INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.Abs
          tractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactor
          y.java:1322)
          [INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.Abs
          tractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.
          java:473)
          [INFO] [talledLocalContainer]   ... 50 more
          [INFO] [talledLocalContainer] Sep 5, 2011 5:49:22 PM org.apache.catalina.core.St
          andardContext start
          [INFO] [talledLocalContainer] SEVERE: Error listenerStart
          [INFO] [talledLocalContainer] Sep 5, 2011 5:49:22 PM org.apache.catalina.core.St
          andardContext start

          Thanks,
          Sreekanth.

          Comment


          • #6
            Sigh... Have you read it... If you want to use load time weaving you have to configure the class loader.

            You still have the SAME exception...

            Comment


            • #7
              how to configure the class loader?

              Please guide me

              Thanks,
              Sreekanth.

              Comment


              • #8
                Do you actually READ the posts? I gave you the link to the configuration TWICE...

                Comment


                • #9
                  Yes i have READ the Posts but you have given the guide lines for Aspectj but i am not using that one, In my application i am using JPA and toplink

                  see the below code

                  Code:
                  <context:load-time-weaver/>
                       <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
                        <property name="dataSource" ref="dataSource"/>      
                        <property name="persistenceXmlLocation" value="META-INF/persistence.xml" />      
                        <property name="loadTimeWeaver">
                              <bean class="org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver"/>
                        </property> 
                  	  <property name="jpaVendorAdapter">
                            <bean class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter">
                              <property name="showSql" value="false"/>                
                      		<property name="databasePlatform" value="oracle.toplink.essentials.platform.database.oracle.OraclePlatform"/>
                            </bean>
                        </property>
                      </bean>
                  
                   <bean id="MydataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
                  	      <property name="jndiName" value="java:comp/env/jdbc/Prepaid_user"/>    
                        <property name="resourceRef" value="true" /> 
                  	</bean>
                  	
                      <!-- Transaction manager for a single JPA EntityManagerFactory (alternative to JTA) -->
                      <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
                            p:entityManagerFactory-ref="entityManagerFactory"/>
                      <context:annotation-config/>
                  in my application Aspect and aop are not using

                  Kindly please guide me
                  Thanks,
                  Sreekanth.

                  Comment


                  • #10
                    Sigh... I give up... I suggest you read the reference guide yourself (and then conclude that eventually end-up in the same location)....I suggest starting at the JPA with load time weaving chapter (which you will then find out links to the section I gave you twice)... To enable load time weaving you need a class loader with certain features, for tomcat this requires another class loader (which is the same for load time weaving and aspects)...

                    Comment


                    • #11
                      I followed your guide lines AOP but still i am not able to get the solution

                      my application is not able to read the JNDI Data source via springs

                      please find the below applicationContext.xml and persiste

                      Code:
                          <context:load-time-weaver/>
                           <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
                            <property name="dataSource" ref="dataSource"/>      
                            <property name="persistenceXmlLocation" value="META-INF/persistence.xml" />      
                            <property name="loadTimeWeaver">
                                  <bean class="org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver"/>
                            </property> 
                      	  <property name="jpaVendorAdapter">
                                <bean class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter">
                                  <property name="showSql" value="false"/>                
                          		<property name="databasePlatform" value="oracle.toplink.essentials.platform.database.oracle.OraclePlatform"/>
                                </bean>
                            </property>
                          </bean>
                          
                         <bean id="MydataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
                      	      <property name="jndiName" value="java:comp/env/jdbc/CNA_user"/>    
                            <property name="resourceRef" value="true" /> 
                      	</bean>
                      	
                          <!-- Transaction manager for a single JPA EntityManagerFactory (alternative to JTA) -->
                          <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
                                p:entityManagerFactory-ref="entityManagerFactory"/>
                          <context:annotation-config/>
                      and META-INF\persistence.xml

                      Code:
                       
                      <?xml version="1.0" encoding="UTF-8"?>
                      <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
                        <persistence-unit name="PrepaidBasicsPU" transaction-type="RESOURCE_LOCAL">
                          <provider>oracle.toplink.essentials.PersistenceProvider</provider>
                          <!-- Connection Pool  -->
                          <non-jta-data-source>java:comp/env/jdbc/CNA_user</non-jta-data-source>
                          <mapping-file>META-INF/orm.xml</mapping-file>
                       	<class>dk.telia.prepaid.persistence.jpa.ReloadAgreement</class>
                          <class>dk.telia.prepaid.persistence.jpa.Creditcard</class>
                          <class>dk.telia.prepaid.persistence.jpa.NotificationAccount</class>
                          <class>dk.telia.prepaid.persistence.jpa.NotificationTemplate</class>
                          <class>dk.telia.prepaid.persistence.jpa.PaymentTransaction</class>
                          <class>dk.telia.prepaid.persistence.jpa.PaymentTransactionDetail</class>
                          <class>dk.telia.prepaid.persistence.jpa.PaymentTransactionDetailPK</class>
                          <class>dk.telia.prepaid.persistence.jpa.AgreementType</class>
                          <!-- Connection  -->
                         <properties>
                               <property name="toplink.jdbc.user" value="CNA"/>
                                  <property name="toplink.jdbc.password" value="CNA_"/>
                                  <property name="toplink.jdbc.url" value="jdbc:oracle:thin:@(DESCRIPTION=xxxx:xxx:,.....">
                                  <property name="toplink.jdbc.driver" value="oracle.jdbc.pool.OracleDataSource"/>
                                  <property name="toplink.logging.level" value="FINE"/>
                                  <property name="toplink.show_sql" value="true"/>     
                         </properties>   
                        </persistence-unit>
                      </persistence>
                      In tomcat/conf/context.xml contains the resource,please see below from tomcat/conf/context.xml
                      Code:
                      <Resource name="jdbc/CNA_user"
                      auth="Container"
                      type="javax.sql.DataSource"
                      removeAbandoned="true"
                      removeAbandonedTimeout="60"
                      logAbandoned="true"
                      maxActive="10"
                      maxIdle="5"
                      maxWait="15000"
                      username="cna_cust2"
                      password="cna_"
                      driverClassName="oracle.jdbc.OracleDriver" url="jdbcracle:thin:@xxx.gggg/>
                      Last edited by aleddullas; Sep 9th, 2011, 02:12 AM.

                      Comment


                      • #12
                        Post the stack trace (and as I stated initially it has nothing to do with your datasource !!!)...

                        Comment


                        • #13
                          Then how i came to know that my application is reading the Datasource?

                          and In my application i am not using servlets, but i want to read log4j.properties from local tomcat/lib

                          below is the stak trace
                          Code:
                          tp11Protocol init
                          [INFO] [talledLocalContainer] INFO: Initializing Coyote HTTP/1.1 on http-8080
                          [INFO] [talledLocalContainer] Sep 9, 2011 2:23:05 PM org.apache.catalina.startup
                          .Catalina load
                          [INFO] [talledLocalContainer] INFO: Initialization processed in 3385 ms
                          [INFO] [talledLocalContainer] Sep 9, 2011 2:23:05 PM org.apache.catalina.core.St
                          andardService start
                          [INFO] [talledLocalContainer] INFO: Starting service Catalina
                          [INFO] [talledLocalContainer] Sep 9, 2011 2:23:05 PM org.apache.catalina.core.St
                          andardEngine start
                          [INFO] [talledLocalContainer] INFO: Starting Servlet Engine: Apache Tomcat/6.0.1
                          8
                          [INFO] [talledLocalContainer] Sep 9, 2011 2:23:06 PM org.apache.catalina.startup
                          .HostConfig deployWAR
                          [INFO] [talledLocalContainer] INFO: Deploying web application archive cargocpc.w
                          ar
                          [INFO] [talledLocalContainer] Sep 9, 2011 2:23:07 PM org.apache.catalina.startup
                          .HostConfig deployWAR
                          [INFO] [talledLocalContainer] INFO: Deploying web application archive prepaid-ba
                          sics.war
                          [INFO] [talledLocalContainer] Sep 9, 2011 2:23:14 PM org.apache.catalina.core.Ap
                          plicationContext log
                          [INFO] [talledLocalContainer] INFO: Set web app root system property: 'prepaid.r
                          oot' = [C:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.18\webapps
                          \prepaid-basics\]
                          [INFO] [talledLocalContainer] Sep 9, 2011 2:23:14 PM org.apache.catalina.core.Ap
                          plicationContext log
                          [INFO] [talledLocalContainer] INFO: Initializing log4j from [C:\Program Files\Ap
                          ache Software Foundation\Apache Tomcat 6.0.18\webapps\prepaid-basics\WEB-INF\log
                          4j.xml]
                          [INFO] [talledLocalContainer] Sep 9, 2011 2:23:14 PM org.apache.catalina.core.Ap
                          plicationContext log
                          [INFO] [talledLocalContainer] INFO: Initializing Spring root WebApplicationConte
                          xt
                          [INFO] [talledLocalContainer] log4j:WARN No appenders could be found for logger
                          (org.springframework.web.context.ContextLoader).
                          [INFO] [talledLocalContainer] log4j:WARN Please initialize the log4j system prop
                          erly.
                          [INFO] [talledLocalContainer] Sep 9, 2011 2:23:16 PM org.apache.catalina.core.St
                          andardContext listenerStart
                          [INFO] [talledLocalContainer] SEVERE: Exception sending context initialized even
                          t to listener instance of class org.springframework.web.context.ContextLoaderLis
                          tener
                          [INFO] [talledLocalContainer] org.springframework.beans.factory.BeanCreationExce
                          ption: Error creating bean with name 'org.springframework.context.weaving.Aspect
                          JWeavingEnabler#0': Initialization of bean failed; nested exception is org.sprin
                          gframework.beans.factory.BeanCreationException: Error creating bean with name 'l
                          oadTimeWeaver': Initialization of bean failed; nested exception is java.lang.Ill
                          egalStateException: ClassLoader [org.apache.catalina.loader.WebappClassLoader] d
                          oes NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a cust
                          om LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaa
                          gent:spring-agent.jar
                          [INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.Abs
                          tractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.
                          java:480)
                          [INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.Abs
                          tractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:40
                          9)
                          [INFO] [talledLocalContainer]   at java.security.AccessController.doPrivileged(N
                          ative Method)
                          [INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.Abs
                          tractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.ja
                          va:380)
                          [INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.Abs
                          tractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
                          [INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.Def
                          aultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
                          [INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.Abs
                          tractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
                          [INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.Abs
                          tractBeanFactory.getBean(AbstractBeanFactory.java:185)
                          [INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.Abs
                          tractBeanFactory.getBean(AbstractBeanFactory.java:164)
                          [INFO] [talledLocalContainer]   at org.springframework.context.support.AbstractA
                          pplicationContext.getBean(AbstractApplicationContext.java:880)
                          [INFO] [talledLocalContainer]   at org.springframework.context.support.AbstractA
                          pplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.jav

                          Comment


                          • #14
                            What on earth is it you want (you are talking about datasources, log4j properties all of which aren't related to the problem)!

                            Again have you READ the stack trace?
                            Code:
                            INFO] [talledLocalContainer] org.springframework.beans.factory.BeanCreationExce
                            ption: Error creating bean with name 'org.springframework.context.weaving.Aspect
                            JWeavingEnabler#0': Initialization of bean failed; nested exception is org.sprin
                            gframework.beans.factory.BeanCreationException: Error creating bean with name 'l
                            oadTimeWeaver': Initialization of bean failed; nested exception is java.lang.Ill
                            egalStateException: ClassLoader [org.apache.catalina.loader.WebappClassLoader] d
                            oes NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a cust
                            om LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaa
                            gent:spring-agent.jar
                            Which is in your stack trace which still points to the fact that you aren't starting tomcat correctly....

                            Again it has nothing to do with a datasource, not with a log4j.properties or log4j.xml you want to read from wherever... It simply has to do with the fact that you haven't configured your tomcat correctly or aren't starting tomcat with the javaagent as specified in the stack trace.

                            Comment


                            • #15
                              Hi,

                              now i am able to read log4j.properties from my local tomcat/lib/lo4j.properties

                              but still i am getting the error please help me

                              Code:
                              [ERROR:http-8080-1] [2011-09-12 11:43:53,444] (DispatcherServlet:290) - Context initialization failed
                              org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'autoMapping' defined in ServletContext resource [/WEB-INF/PrepaidBasics-servlet.xml]: 
                              Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'noBillController': 
                              Injection of resource fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'thresholdReloadService': Injection of 
                              resource fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'thresholdReload': Injection of resource fields failed; 
                              nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [dk.telia.prepaid.persistence.jpa.PaymentDao] is defined: Unsatisfied
                              dependency of type [interface dk.telia.prepaid.persistence.jpa.PaymentDao]: expected at least 1 matching bean
                              My dispatcher-servlet contains the following:

                              Code:
                              <bean id="autoMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
                                      <property name="mappings">
                                          <value>notification=noBillController</value>   
                                      </property>
                                  </bean>
                              <bean name="thresholdReloadService" class="us.cna.prepaid.reload.ThresholdReloadServiceImpl"/>
                              <bean name="thresholdReload" class="us.cna.prepaid.reload.ThresholdReloadStoredProcImpl">
                              Last edited by aleddullas; Sep 12th, 2011, 01:33 AM.

                              Comment

                              Working...
                              X