亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

測試exposerSeckillUrl出現@Service 下@Autowired注入失敗的 出現NullPointerException!!百度找不到辦法

@Service
public?class?SeckillServiceImpl?implements?SeckillService?{
???private?Logger?logger?=?LoggerFactory.getLogger(this.getClass());
???//注入Service依賴,
???@Autowired
???private?SeckillDao?seckillDao;?//提示?Cannot?autowired?,no?beans?of?'seckillDao'
???@Autowired
???private?SuccessKilledDao?successKilledDao;?//提示?Cannot?autowired?,no?beans?of?'successKilledDao'

java.lang.NullPointerException

at org.seckill.service.impl.SeckillServiceImpl.exportSeckillUrl(SeckillServiceImpl.java:53)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)

at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:201)

at com.sun.proxy.$Proxy19.exportSeckillUrl(Unknown Source)

at org.seckill.service.SeckillServiceTest.testexportSeckillUrl(SeckillServiceTest.java:43)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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)


正在回答

2 回答

都是淚,搞了4個小時了快,@Autowired注入失敗? ?seckillDao successKilledDao 有紅色的下劃線

我的解決辦法是把idea換成2017的版本就沒有紅色下劃線了,順帶還解決了2018版本idea創建接口測試實例不能選

中并自動生成測試方法。

NullPointerException?空指針異常? 我本以為也是版本問題,不過重裝后沒有解決,然后我我報錯是這一句

if?(nowTime.getTime()?<?startTime.getTime()?||?nowTime.getTime()?>?endTime.getTime()){

然后改成?if(1 == 0)就通過了測試,所以我又改回來并把斷點打在這一步然后debug發現開始時間沒有值即

startTime = null?然后就發現是seckill實體類seckillId寫成?seckill?和?startTime?寫成starTime !連累setget方法也

錯了 最后把這個實體類重寫一遍寫對就可以了,開始時間就有值了也就沒有空指針異常引起的報錯了測試也就通過

了!所以空指針就debug跑一下應該就能發現是哪兒出錯了,idea的debug好好用!如果我的解決方法可以幫到你

麻煩點個贊!雖然我有點啰嗦


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

weixin_慕神4066351

我也出現這個問題,但是我實體類沒寫錯,難熬哦
2022-02-22 回復 有任何疑惑可以回復我~

spring-service.xml配置不對吧,或者測試類有問題

1 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

測試exposerSeckillUrl出現@Service 下@Autowired注入失敗的 出現NullPointerException!!百度找不到辦法

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號