Announcement Announcement Module
Collapse
No announcement yet.
spring-social-showcase-xml with local database datasource Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring-social-showcase-xml with local database datasource

    Hi I'm totally beginner in spring framework and spring social, I already download the the spring-social-showcase-xml that using xml configuration it run perfectly, but in this example use some embed datasource.

    I need to configure it so it can using my local database as datasource, I already have account table, and userconnection table in my local database.

    Now if I'm correct the datasource configuration in org.springframework.social.showcase.config.MainCon fig.java, so which point and how to modify it, so I can use my local database as datasource?, any help either with java or xml configuration it's okay as long I can use my local database as datasource.

    I'm using mysql and already add the dependency for mysql

    Code:
    	<dependency>
    		<groupId>mysql</groupId>
    		<artifactId>mysql-connector-java</artifactId>
    		<version>5.1.9</version>
    	</dependency>
    any suggestion please

  • #2
    I've essentially answered this same question in this thread: http://forum.springsource.org/showth...dbc-properties.

    Again, this isn't so much of a Spring Social matter and more of a core Spring matter of replacing one data source bean with another one. What you'll want to do is replace the dataSource() method in MainConfig.java with one that creates and returns an instance of a non-embedded datasource...such as DriverManagerDataSource, SimpleConnectionDataSource, or SingleConnectionDataSource. You may also choose to return a DataSource created from one of the many 3rd party connection pools that play nice with Spring. Or possibly replace it with one that looks up the DataSource from JNDI.

    The choice you make here depends on what you have in mind for your app. Certainly a connection pool or JNDI-retrieved DataSource is going to be more production-ready than SingleConnectionDataSource. But SingleConnectionDataSource is simple and "just works" with minimal configuration and is suitable for testing and experimentation purposes.

    There are *many* examples of configuring all kinds of data sources in Spring all over the internet and since this problem isn't Spring Social-specific, you can draw on any of those examples as a guide. Here are a couple of places you can look for guidance:

    - Spring Framework Reference: file://localhost/Users/habuma/Applications/spring-3.2.0.M1/docs/reference/htmlsingle/index.html#jdbc-datasource
    - Greenhouse (uses H2 JdbcConnectionPool): https://github.com/SpringSource/gree...ataConfig.java

    I also showed an XML-based configuration of SimpleDriverDataSource in the other thread mentioned above.

    Comment

    Working...
    X