问答详情
源自:4-1 转账环境的搭建

java.lang.NullPointerException这是怎么回事?我跟着做的,求解决

<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:task="http://www.springframework.org/schema/task"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
         http://www.springframework.org/schema/context
         http://www.springframework.org/schema/context/spring-context-3.1.xsd
         http://www.springframework.org/schema/aop
         http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
         http://www.springframework.org/schema/tx
         http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
         http://www.springframework.org/schema/task
		 http://www.springframework.org/schema/task/spring-task-3.1.xsd">

	<context:property-placeholder location="classpath:jdbc.properties" />
	<bean id="dateSource" 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>

	<bean id="accoutService" class="cn.muke.spring.demo1.AccoutServiceImpl">
		<property name="accountDao" ref="accountDao"></property>
	</bean>

	<bean id="accountDao" class="cn.muke.spring.demo1.AccountDaoImpl">
		<property name="dataSource" ref="dataSource"></property>
	</bean>

</beans>
package cn.muke.spring.demo1;

import org.springframework.jdbc.core.support.JdbcDaoSupport;

public class AccountDaoImpl extends JdbcDaoSupport implements AccountDao {

	public void outMoney(String out, Double money) {
		String sql = "update account set money = money - ? where out = ?";
		this.getJdbcTemplate().update(sql, money, out);

	}

	public void inMoney(String in, Double money) {
		String sql = "update account set money = money + ? where in = ?";
		this.getJdbcTemplate().update(sql, money, in);

	}

}
package cn.muke.spring.demo1;

public class AccoutServiceImpl implements AccountService {

	private AccountDao accountDao;
	
	public void setAccountDao(AccountDao accountDao) {
		this.accountDao = accountDao;
	}


	public void transfer(String out, String in, Double money) {
		accountDao.outMoney("aaa", 200d);
		accountDao.inMoney("bbb", 200d);
	}

}
package cn.muke.spring.demo1;

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.springframework.test.context.ContextConfiguration;

@RunWith(BlockJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext1.xml")
public class AccountTest {
	@Resource(name = "accoutService")
	private AccountService accoutService;
	
	@Test
	public void testDome(){
		accoutService.transfer("aaa", "bbb", 200d);
	}

}



提问者:风鹤子 2016-08-04 22:19

个回答

  • 慕粉3771866
    2016-08-05 15:26:09
    已采纳

    http://img.mukewang.com/57a43f7b0001033d05940308.jpg

    名称写错了

  • withyou王杰
    2016-09-11 23:28:27

    http://img.mukewang.com/57d577f9000162ee05580340.jpg这里变量,并不是值

  • 慕标3904527
    2016-08-05 10:54:29

    错误代码全部贴出来啊