How to Define a MySql datasource bean via XML in Spring

cyotee doge picture cyotee doge · Sep 30, 2012 · Viewed 83.4k times · Source

I've looked over the documentation to define a bean. I'm just unclear on what class file to use for a Mysql database. Can anyone fill in the bean definition below?

<bean name="dataSource" class="">
    <property name="driverClassName" value="" />
    <property name="url" value="mysql://localhost/GameManager" />
    <property name="username" value="gamemanagertest" />
    <property name="password" value="1" />
</bean>

Answer

cyotee doge picture cyotee doge · Sep 30, 2012
<bean name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost:3306/GameManager" />
    <property name="username" value="gamemanagertest" />
    <property name="password" value="1" />
</bean>

http://docs.spring.io/spring-data/jdbc/docs/1.1.0.M1/reference/html/orcl.datasource.html