ApplicationContext ctx=new ClassPathXmlApplicationContext("classpath*:springService.xml");
ServiceA serviceA = (ServiceA ) ctx.getBean("serviceA "); 其中springService.xml中定义了bean serviceA ,但springService.xml与该段java不在同一个目录这样取不到serviceA,请问问题出在哪?
Many thanks!!
ServiceA serviceA = (ServiceA ) ctx.getBean("serviceA "); 其中springService.xml中定义了bean serviceA ,但springService.xml与该段java不在同一个目录这样取不到serviceA,请问问题出在哪?
Many thanks!!
解决方案 »
- java为什么要将jar文件转化为exe文件???
- 去上一周的日期
- jar 运行 报错链接hibernate3属性文件错误。急。。。急。。求解
- oracle连接
- hibernate update问题
- Tomcat用户登录问题(admin)?
- java 中堆和堆栈的问题
- 一个关于PreparedStatement语句的问题,请教各位高手~
- 爽极,散分,sun one application server7 + mysql,struts,连接池什么的都配好了,爽啊,真爽!!!!!!
- 大神们帮忙解答下添加在hashset中的元素为什么要实现hashcode和equals方法
- 请教如何循环 字母加数字 更优化?
- 怎样实现一定时间内执行业务次数(如投票功能)
这一步没有得到,难道是ctx是错误的?再问下全路径怎么写,我java文件与配置文件隔好远
之前我是用ApplicationContext ctx=new ClassPathXmlApplicationContext("springService.xml");
没有classpath*:,发现得不到ctx
然后网上查了下用classpath*可以得到ctx
但ServiceA serviceA = (ServiceA ) ctx.getBean("serviceA "); 这句完后报错,not found source
我springService.xml是这样<bean id="serviceA"
class="com.XXX.XX.service.bean.ServiceA"
/>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springService-*.xml,classpath*:springService.xml,classpath*:springService-*.xml</param-value>
</context-param> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
在springService.xml中定义了
<bean id="serviceA"
class="com.XXX.XX.service.bean.ServiceA"
/>
而serviceA在com.XXX.XX.service.bean.ServiceA这个目录底下我的代码如下:ApplicationContext ctx=new ClassPathXmlApplicationContext("classpath*:springService.xml");
ServiceA serviceA = (ServiceA ) ctx.getBean("serviceA");
return serviceA .isMethod();可以通过ApplicationContext ctx=new ClassPathXmlApplicationContext("classpath*:springService.xml");获得ctx
但执行到ServiceA serviceA = (ServiceA ) ctx.getBean("serviceA"); 就报错source not found请教什么原因啊?
问题应该就出在这两个路径上的
actionServlet.init();
ServletContext servletContext = actionServlet.getServletContext();
WebApplicationContext webApplicationContext =
(WebApplicationContext) servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
ServiceA serviceA=
(ServiceA ) webApplicationContext.getBean("serviceA");
return serviceA.isxx();
执行到ServletContext servletContext = actionServlet.getServletContext();这里就报错 了请教是什么原因哦,郁闷