1. Put the residence of the imitation database connection in spring.xml
<?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:context="http://www.springframework.org/schema/context"
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/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
//connect to mysql database
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close" >
<property name="driverClassName" value="com.mysql.jdbc.Driver">
</property>
<property name="url" value="jdbc:mysql://192.168.1.3:3306/mlxcdb">
</property>
<property name="username" value="root"></property>
<property name="password" value="mysql"></property>
</bean>
2. Put the relevant driver information about the connection to the database connection in the jdbc.properties configuration file
- <!-- Use properties file to configure data source -->
- <beanid="propertyPlaceholderConfigurer"class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <propertyname="location"value="jdbc.properties"/>
- </bean>
- <beanid="dataSource"class="org.springframework.jdbc.datasource.DriverManagerDataSource"destroy-method="close">
- <propertyname="driverClassName"value="${jdbc.driverClassName}"/>
- <propertyname="url"value="${jdbc.url}"/>
- <propertyname="username"value="${jdbc.username}"/>
- <propertyname="password"value="${jdbc.password}"/>
- </bean>
//connect to mysql database
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://192.168.1.3:3306/mlxcdb
jdbc.username=root
jdbc.password=mysql