Announcement Announcement Module
Collapse
No announcement yet.
How To Configure Spring MVC 3 With JDBC for Mysql Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How To Configure Spring MVC 3 With JDBC for Mysql

    I am working on a small web project in java and Spring3 MVC. Although I have been studying java for the past 5 months, this is my first time making anything substantial with either of these technologies.

    The problem I am having is setting up a Mysql database connection using Dependency Injection in the Spring applicationContext.xml file.

    I build a new project in NetBeans and do the following:
    1. Include Spring3 with Dependency Injection
    2. Import mysql JDBC library
    3. Create a jdbc.properties file with associated name value pairs
    4. Run project (works fine)
    5. Configure Database connection in applicationContext.xml
    6. Re load Project
    7. Build Fails

    This is my applicationContext.xml and jdbc.properties
    Code:
        <?xml version="1.0" encoding="UTF-8"?>
        <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:p="http://www.springframework.org/schema/p"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="http://www.springframework.org/schema/beans     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
    
        <bean id="propertyConfigurer"
              class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
              p:location="/WEB-INF/jdbc.properties" />
    
        <bean id="dataSource"
              class="org.springframework.jdbc.datasource.DriverManagerDataSource"
              p:driverClassName="${jdbc.driverClassName}"
              p:url="${jdbc.url}"
              p:username="${jdbc.username}"
              p:password="${jdbc.password}" />
    
        <!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
        </beans>
    This is the jdbc.properties
    Code:
        driverClassName=com.mysql.jdbc.Driver
        url=jdbc:mysql://localhost:3306/bcash
        username=root
        password=myPassword
    I have spent the best part of a week trying to configure Spring3, I have also been reading through Spring in Action and Spring Recipes, but I can't seem to get past the first hurdle of just configuring the Spring Container.

    Am I overlooking something simple?

    Any help is truly appreciated, thanks in advance
Working...
X