【发布时间】:2014-01-25 13:12:17
【问题描述】:
我正在学习来自
的教程http://www.mkyong.com/spring/maven-spring-jdbc-example/
我以前没有使用过 bean,本教程中的一件事让我感到困惑
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="customerDAO" class="com.mkyong.customer.dao.impl.JdbcCustomerDAO">
<property name="dataSource" ref="dataSource" />
</bean>
</beans>
这是一个 bean 文件,其中包含一个 bean,它将 JDBCCustomerDao 中的 dataSource 变量设置为 dataSource,这是该文件中包含的另一个 bean:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/mkyongjava" />
<property name="username" value="root" />
<property name="password" value="password" />
</bean>
到目前为止,我了解 JdbcCustomerDao 的 dataSource 变量设置为具有属性
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/mkyongjava" />
<property name="username" value="root" />
<property name="password" value="password" />
但是我不确定 url 指向什么。是可以找到我的数据库的网址吗?它是我可以在其中创建 dbs 的目录吗?
可能这个问题有一个非常简单的答案,但我不确定,谷歌搜索并没有真正帮助。
谢谢
【问题讨论】:
标签: java database jdbc javabeans