Announcement Announcement Module
Collapse
No announcement yet.
spring 3.2 + jboss 7.1.1: how to get the datasource from jndi Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring 3.2 + jboss 7.1.1: how to get the datasource from jndi

    I have to go into production with my web application. The application server is JBoss 7.1.1.
    So I was looking for moving the datasources from the spring application context to the container.
    I configured the datasource in jboss:

    Code:
    <datasource jta="false" jndi-name="java:jboss/datasources/sampleDS" pool-name="sampleDSPool" enabled="true" use-java-context="true" use-ccm="false">
                        <connection-url>jdbc:postgresql://localhost:5432/sampleDB</connection-url>
                        <driver-class>org.postgresql.Driver</driver-class>
                        <driver>postgresql</driver>
                        <pool>
                            <min-pool-size>2</min-pool-size>
                            <max-pool-size>20</max-pool-size>
                        </pool>
                        <security>
                            <user-name>*****</user-name>
                            <password>*****</password>
                        </security>
                        <validation>
                            <validate-on-match>false</validate-on-match>
                            <background-validation>false</background-validation>
                            <background-validation-millis>1</background-validation-millis>
                        </validation>
                        <statement>
                            <prepared-statement-cache-size>0</prepared-statement-cache-size>
                            <share-prepared-statements>false</share-prepared-statements>
                        </statement>
                    </datasource>
    Well, when jboss starts it confirms that my datasource it's bound to java:jboss/datasources/sampleDS.

    Now I wanted to move the configuration:

    Code:
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    			<property name="driverClassName" value="${db.driver.prod}" />
    			<property name="url" value="${db.url.prod}" />
    			<property name="username" value="${db.username.prod}" />
    			<property name="password" value="${db.password.prod}" />
    		</bean>
    to

    Code:
    <jee:jndi-lookup id="dataSource" jndi-name="java:jboss/datasources/sampleDS"/>
    or

    Code:
    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    			<property name="jndiName">
    				<value>java:jboss/datasources/sampleDS</value>
    			</property>
    		</bean>
    There is no way of getting the datasource from jboss, I always end with name not found ( I tried almost every combination ).
    Code:
    Caused by: javax.naming.NameNotFoundException: jboss/datasources/sampleDS -- service jboss.naming.context.java.jboss.exported.jboss.datasources.sampleDS
    Is there someone that is able to use the datasource fomr joss through jndi?
    Thank you for your help.

    Daniele

  • #2
    Anyone had the problem of getting the datasource from jndi with the last versions?

    Comment


    • #3
      Hi,

      try to change the jndi-name to "java:/datasources/sampleDS" in your standalone.xml and spring configuration.
      I had the same problem and solved it by removing "jboss" from the jndi-name.

      I hope this helps.
      Cheers
      Dirk

      Comment


      • #4
        Changing only your spring config to
        Code:
        <jee:jndi-lookup id="dataSource" jndi-name="java:/jboss/datasources/sampleDS"/>
        should work, too

        Dirk

        Comment


        • #5
          Hi all,
          for some reason using
          Code:
          <jee:jndi-lookup id="dataSource" jndi-name="java:jboss/datasources/sampleDS"/>
          started to work. I already tried it, but for some reason now it's working.
          In order for it to work properly on jboss 7 I had to add the dependency for "org.jboss.ironjacamar.jdbcadapters" in the manifest of my war.
          Unfortunately another problem popped out. If I use the jndi datasource I'm not able to resolve anymore properties in the properties files. They are loaded correctly but I end up with the message
          Code:
          Could not resolve placeholder 'placeholder_string_value'
          .
          Any thoughts?

          Edit:
          The dependency org.jboss.ironjacamar.jdbcadapters is causing the problem, trying to figure out how to solve it.
          If anyone can help is appreciated.

          Regards,
          Daniele
          Last edited by settholo; Feb 7th, 2013, 09:01 AM.

          Comment


          • #6
            Packing the application with the library
            Code:
            <dependency>
            	<groupId>org.jboss.ironjacamar</groupId>
            	<artifactId>ironjacamar-jdbc</artifactId>
            	<version>1.0.9.Final</version>
            </dependency>
            and removing the dependency for jboss solved the problem.
            Don't know the reason, the bundled version is the same and the latest stable available.
            Regards,

            Daniele

            Comment

            Working...
            X