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

空指针异常


<?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/aop
        http://www.springframework.org/schema/aop/spring-util.xsd
        http://www.springframework.org/schema/tx
        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.driver}"/>
        <property name="jdbcUrl" value="${jdbc.url}"/>
        <property name="user" value="${jdbc.user}"/>
        <property name="password" value="${jdbc.password}"/>

    </bean>

    <!-- 配置业务类 -->
    <bean id="accountService" class="com.demo.AccountServiceInpl">
        <property name="accountDao" ref="accountDao"/>
        <context:component-scan base-package="com.demo"/>

    </bean>
    <!-- 配置dao类 -->
    <bean id="accountDao" class="com.demo.AccountDaoImpl">
        <property name="dataSource" ref="dataSource"></property>
    </bean>

配置文件如上图  不知道问题在哪

正在回答

7 回答

<context:component-scan base-package="com.demo"/>

你把这行配置放到<bean>外边试试,不行我也看不出有什么毛病了

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

冰舞魅火 提问者

好吧 还是谢谢你了
2018-08-05 回复 有任何疑惑可以回复我~

c3p0连接池用户名那行确定是${jdbc.user}?,应该不是的吧

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

咦?回复怎么这么奇怪?com.demo.AccountServiceInpl改成com.demo.AccountServiceImpl

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

冰舞魅火 提问者

(⊙o⊙)… 名字确实错了 但是我在bean配置的名字和实现类名字是一样的 错误应该不在这吧
2018-08-05 回复 有任何疑惑可以回复我~

application配置文件 id为accountService的bean类名称写错了吧  

class="com.demo.AccountService"  应该是com.demo.'AccountService


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

https://img1.sycdn.imooc.com//5b668fdd0001456109570405.jpg 不知道空指针发生在哪  代码应该没问题

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


java.lang.NullPointerException

at com.demo.Test1.Test1(Test1.java:22)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.base/java.lang.reflect.Method.invoke(Method.java:564)

at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)

at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)

at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)

at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)

at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)

at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)

at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)

at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)

at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)

at org.junit.runners.ParentRunner.run(ParentRunner.java:363)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)

at org.junit.runner.JUnitCore.run(JUnitCore.java:137)

at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)

at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)

at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)

at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)



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

报错信息发上来

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

举报

0/150
提交
取消
Spring事务管理
  • 参与学习       87318    人
  • 解答问题       197    个

事务管理是Spring重要的知识,应用事务解决数据不一致问题

进入课程

空指针异常

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