<?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:aop="http://www.springframework.org/schema/aop"? ? ? ?xmlns:tx="http://www.springframework.org/schema/tx"? ? ? ?xmlns:context="http://www.springframework.org/schema/context"? ? xsi:schemaLocation="? ? ? ?http://www.springframework.org/schema/beans? http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx? http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop? http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context? http://www.springframework.org/schema/context/spring-context.xsd? ? ? ? ">? ?<!-- 加載配置文件 -->? ?<context:property-placeholder location="classpath:jdbc.properties"/>? ?? ?<!-- 配置c3p0連接池 -->? ?<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">? ? ? ?<property name="driverClass" value="${jdbc.driverClass}" />? ? ? ?<property name="jdbcUrl" value="${jdbc.url}" />? ? ? ?<property name="user" value="${jdbc.username}" />? ? ? ?<property name="password" value="${jdbc.password}" />? ?</bean>? ?<!-- 業(yè)務 -->? ?<bean id="accountService" class="cn.itcast.spring.Demo.AccountDaoImpl">? ? ? ?<property name="accountDao" ref="accountDao"></property>? ?</bean>? ?? ?<!-- dao -->? ?<bean id="accountDao" class="cn.itcast.spring.Demo.AccountDaoImpl">? ? ? ?<property name="dataSource" ref="dataSource"></property>? ?</bean>?</beans>package cn.itcast.spring.Demo;import javax.annotation.Resource;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration("classpath:applicationContext.xml")public class SpringTest { @Resource(name="accountService") private AccountService accountService; @Test public void test1(){ accountService.transfer("aaa", "bbb", 100d); } }
1 回答

慕圣0830664
TA貢獻41條經(jīng)驗 獲得超26個贊
?<!-- 業(yè)務 -->
? ?<bean id="accountService" class="cn.itcast.spring.Demo.AccountDaoImpl">
<!-- dao -->
? ?<bean id="accountDao" class="cn.itcast.spring.Demo.AccountDaoImpl">
@Resource(name="accountService")
private AccountService accountService;
看下這幾句有什么問題沒?已經(jīng)很明顯了,對象的類型不匹配。
添加回答
舉報
0/150
提交
取消