Announcement Announcement Module
Collapse
No announcement yet.
Using database command in connection with a persistence setup with jndiDataSource Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using database command in connection with a persistence setup with jndiDataSource

    I'm using a persistence setup using a jndiDataSource:

    persistence setup --database MYSQL --provider ECLIPSELINK --databaseName mydb --jndiDataSource jdbc/mydb

    When I now try to inspect that database

    database introspect --schema mydb

    it says:

    Connection properties must not be null or empty

    Shouldn't spring roo take the connection properties from the jndi data source? I probably have to connect a running server somehow to Spring Roo, but how?

    Thank you very much

  • #2
    Yes, DBRE just uses the database.properties URL etc to make live connections at present. Raise an improvement request if you like for jndi. Will probably have to use something like:

    Code:
    Connection connection = null;
    try {
       InitialContext context = new InitialContext();
       DataSource dataSource = (DataSource) context.lookup("jdbc/DataSource");
       connection = dataSource.getConnection();
    } catch (Exception e) {
       ...
    }
       return connection;
    }

    Comment


    • #3
      Ah ok

      Well, it's no problem for development but I don't want any properties file for deployment.
      I don't think time is saved when using JNDI because you would have to manually connect to/start the server first.

      The 'solution' I guess is:

      1. create configuration with local db configuration:
      persistence setup --database MYSQL --provider ECLIPSELINK --databaseName mydb --userName asdf --password jklm
      2. also register jndi data source
      persistence setup --database MYSQL --provider ECLIPSELINK --databaseName mydb --jndiDataSource jdbc/mydb

      ...
      development
      ...

      For release: delete database.properties
      Last edited by Clawg; Nov 29th, 2011, 04:51 AM.

      Comment


      • #4
        Not that it would help with DBRE, but in my previous job I declared the following config to read properties out of JDNI, but it also defaulted to a properties file if the JNDI object could not be found. So the same configuration worked in either WebSphere or Tomcat with the same WAR file:

        Code:
        	<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        		<property name="properties">
        			<bean class="org.springframework.jndi.JndiObjectFactoryBean">
        				<property name="jndiName" value="config/FOO" />
        				<property name="resourceRef" value="true" />
        				<property name="defaultObject" ref="coreProperties" />
        			</bean>
        		</property>
        		<property name="ignoreUnresolvablePlaceholders" value="true" />
        	</bean>
        	<bean id="coreProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        		<property name="locations">
        			<util:list>
        				<value>classpath:env/${FOO_ENV}/database.properties</value>
        				<value>classpath:env/${FOO_ENV}/ldap.properties</value>
        				<value>classpath:META-INF/spring/mail.properties</value>
        			</util:list>
        		</property>
        		<property name="ignoreResourceNotFound" value="true" />
        	</bean>

        Comment

        Working...
        X