当前位置: 代码迷 >> J2EE >> jsp页面获取注入的spring bean 求高手来看看解决思路
  详细解决方案

jsp页面获取注入的spring bean 求高手来看看解决思路

热度:115   发布时间:2016-04-22 01:15:12.0
jsp页面获取注入的spring bean 求高手来看看
Java code
jsp页面获取注入的spring bean <%@page import="org.springframework.context.ApplicationContext"%><%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%><%ApplicationContext context = WebApplicationContextUtils. getWebApplicationContext(application);MstAllMapTypeServiceImpl service =(MstAllMapTypeServiceImpl)context.getBean("mstAllMapTypeServiceImpl");  %>说不能强转成 我想要的类不知道怎么解决 严重: Servlet.service() for servlet jsp threw exceptionjava.lang.ClassCastException: $Proxy28 cannot be cast to com.common.service.impl.MstAllMapTypeServiceImplat org.apache.jsp.carmap_jsp._jspService(org.apache.jsp.carmap_jsp:109)未完……


------解决方案--------------------
注入的Bean是代理的
不要用具体的Impl类型,用父接口类型强转试试看。
------解决方案--------------------
请检查配置文件看看,mstAllMapTypeServiceImpl 这个bean 的Class配置是否为MstAllMapTypeServiceImpl。

可以尝试转换为 MstAllMapTypeService 这个接口看看,我觉得应该不是这个问提。

仔细看看对应的包路径是否一致。
------解决方案--------------------
应该是接口名:
MstAllMapTypeService service =
(MstAllMapTypeService)context.getBean("MstAllMapTypeService");
另外你的spring配置文件
<bean id="mstAllMapTypeService" class="包名.mstAllMapTypeServiceImpl"/>
------解决方案--------------------
MstAllMapTypeServiceImpl service =
(MstAllMapTypeServiceImpl)context.getBean("mstAllMapTypeServiceImpl");

这里不能用实现类转换

得用 MstAllMapTypeServiceImpl 的接口,换 接 口 吧
------解决方案--------------------
spring 注入的mstAllMapTypeServiceImpl 是个什么?接口还是类?
  相关解决方案