此次我是为了更好的记忆而解析与专注于xml和注释,所以忽略其中代码,只放了层次
<bean name="accountService" class="com.itheima.service.impl.AccountServiceImpl">
<property name="accountdao" ref="accountdao"></property>
</bean>
<bean name="accountdao" class="com.itheima.dao.impl.AccountDaoImpl.java">
<property name="runner" ref="runner"></property>
</bean>
xml第一个写的bean就是业务层的实现类,name略过不讲,class是他的全限定名,property是因为AccountServiceImpl中是要调用AccountDaoImpl(业务层调用持久层),所以DI了进去。ref的名是和想调用的name一样的;第二个bean也一样就略过
上面一个ref了runner,代码也是调用了QueryRunner,这不是我们自己创建的类,只能配置一个QueryRunner的bean(配置类)
我们用的是他的构造方法,所以用了constructor-arg,然后继续传递下去-dataSource
<bean name="runner" class="org.apache.commons.dbutils.QueryRunner" scope="prototype">
<constructor-arg name="ds" ref="dataSource"></constructor-arg>
</bean>
此处与上一个一样,不过这个下一个文章用注释更好讲
<bean id="dateSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/eesy"></property>
<property name="user" value="root"></property>
<property name="password" value="123"></property>
</bean>