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

default-autowire="byName"

有个问题就是 service类中的私有成员变量 的名字一定要和 set方法函数参数的名字一样吗?如果不一样的话,byName 相同的是哪个名字?

 按照课上的例子,将<bean id="autoWiringDAO" class="autowiring.AutoWiringDAO" ></bean>这行代码中的id 改为autoWiringDAO1 后, 我又将AutoWiringService中的私有成员变量改为autoWiringDAO1以及set方法的参数改为autoWiringDAO1。运行结果

java.lang.Error: Unresolved compilation problem: 

autoWiringDAO1 cannot be resolved or is not a field


at autowiring.AutoWiringService.say(AutoWiringService.java:18)

at test.TestAutoWiring.testSay(TestAutoWiring.java:19)

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

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

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

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

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

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

at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)

at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)

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

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)

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

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

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

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

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

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

at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)

at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)


正在回答

2 回答

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

其实这里应该将setAutoWiringDao改为setAutoWiringDao1

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

举报

0/150
提交
取消

default-autowire="byName"

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