整个系统运行正常,功能也无问题,只是我在写junit测试的时候获取service的bean无法得到实体,如果我把bean里面改个错误的名称又会报错,证我我配置也应该没有问题,而且获取DAO跟controller层都是可以的,就是service为空,求大神帮忙,如下:
ApplicationContext context = new FileSystemXmlApplicationContext( new String []{
"classpath:applicationContext-core.xml", "classpath:applicationContext-dao.xml",
"classpath:applicationContext-service.xml","classpath:spring-mvc.xml" });
testService = (TestService) context.getBean("testService"); =========结果为null
testDao = (TestDao) context.getBean("testDao"); =========可以取到值
testController = (TestController) context.getBean("testController");=======可以取到值
testController -----spring-mvc.xml 里面
<bean id="testController" class="com.lmxf.post.test.web.TestController">
<property name="methodNameResolver">
<ref bean="methodNameResolver" />
</property>
<property name="testService">
<ref bean="testService" />
</property>
</bean>
testDao -----------applicationContext-dao.xml
<bean id="testDao" class="com.lmxf.post.test.repository.TestDao">
<property name="sessionFactory" ref="sqlSessionFactory"/>
</bean>
testService ---------applicationContext-service.xml
<bean id="testService" class="com.lmxf.post.test.service.TestService">
<property name="testDao" ref="testDao"/>
</bean>
系统运行的时候正常的,就是我写junit测试无法到service层进得测试,运行又无异常,完全通过,只是调用testService的方法时不有进去,testService 改一下又会报异常,说明我这里应该也没有问题,我试了一下别的模块,也都如上,就只是service获取不到,求大神!!
------解决思路----------------------
testDao = (TestDao) context.getBean("testDao");这样写看看能取到不
testService = (TestService) context.getBean("testService");
testController = (TestController) context.getBean("testController");
------解决思路----------------------
ApplicationContext context = new ClassPathXmlApplicationContext( new String []{
"applicationContext-core.xml", "applicationContext-dao.xml",
"applicationContext-service.xml","spring-mvc.xml" });
------解决思路----------------------
TestService代码贴一下
------解决思路----------------------
debug “context.getBean("testService")”这个的结果是什么,强转可能会出现null。
------解决思路----------------------
我记得可以applicationContext-*来做的;话说为什么写4个参数进去。。
------解决思路----------------------
你这个结果是null、
还是你想说是空指针异常呢?
------解决思路----------------------
通过controller get方法获取的service 是什么?