为了账号安全,请及时绑定邮箱和手机立即绑定

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);
	}

}



正在回答

4 回答

http://img1.sycdn.imooc.com//57a43f7b0001033d05940308.jpg

名称写错了

0 回复 有任何疑惑可以回复我~
#1

风鹤子 提问者

谢谢,我已经改过来了,但还是提示空指针
2016-08-07 回复 有任何疑惑可以回复我~
#2

慕粉3771866 回复 风鹤子 提问者

你把这个贴出来 classpath:applicationContext1.xml 可能是配置文件不对
2016-08-08 回复 有任何疑惑可以回复我~
#3

风鹤子 提问者 回复 慕粉3771866

应该是jar包问题,全部换成老师的jar包就通过了
2016-08-10 回复 有任何疑惑可以回复我~

fopen(#39;./test.txt#39;,nbsp;#39;w#39;);表示用写入方式打开#39;./test.txt文件,fwrite是写入操作

ozfgwzrqm

0 回复 有任何疑惑可以回复我~

http://img1.sycdn.imooc.com//57d577f9000162ee05580340.jpg这里变量,并不是值

0 回复 有任何疑惑可以回复我~

错误代码全部贴出来啊

0 回复 有任何疑惑可以回复我~
#1

风鹤子 提问者

console里没有输出,junit里就这一句提示
2016-08-07 回复 有任何疑惑可以回复我~
#2

orex 回复 风鹤子 提问者

@RunWith(SpringJUnit4ClassRunner.class)
2016-10-11 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

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

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信