Announcement Announcement Module
Collapse
No announcement yet.
Spring3 Security JDBC how to load connect info Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring3 Security JDBC how to load connect info

    Spring3 Security JDBC how to load connect info

    I been working on this sample of Spring3 Security JDBC for 2 weeks now and I got it working but adding the dataSource been to the ApplicationContext but now I cant get it loading the connection inform from my file. I hard coded it and it works but I would like it to load from a file. can someone please tell me what I am missing from my AppicationContext to get it to work.. thanks


    ApplicationContext-Security.xml

    Code:
    <beans:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <beans:property name="driverClassName" value="${database.driver}" />
    <beans:property name="url" value="${database.url}" />
    <beans:property name="username" value="${database.user}" />
    <beans:property name="password" value="${database.password}" />
    </beans:bean>
    Changed to following and it works:

    Code:
    <beans:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <beans:property name="url" value="jdbc:mysql://127.0.0.1/db_mytest" />
    <beans:property name="username" value="root" />
    <beans:property name="password" value="" />
    </beans:bean>
    but I dont want to hard code it. please help me.

  • #2
    I think you need a property configurer:

    Code:
      <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    
                <property name="location"><value>classpath:some/place/jdbc.properties</value></property>
    
          </bean>
    This file should have username and passord in it.

    If you want it to be secure you should wrap you datasource in a secure datasource, i.e. UserCredentialsDataSourceAdapter.

    Edit: and url and driver

    Comment


    • #3
      thanks, coding is not the same but working

      Thanks, it works I don't know why my format dont match yours but I got it working but

      adding:
      Code:
      <beans:bean id="propertyConfigurer"
      		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
      		<beans:property name="location" value="classpath:jdbc.properties" />
      	</beans:bean>

      And changing the dataSource bean to:
      Code:
      	<beans:bean id="dataSource"
      		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      		<beans:property name="driverClassName" value="${database.driver}" />
      		<beans:property name="url" value="${database.url}" />
      		<beans:property name="username" value="${database.user}" />
      		<beans:property name="password" value="${database.password}" />
      	</beans:bean>
      Is my XML format diff due to the version of Spring I am running?

      Comment

      Working...
      X