解决方案 »
- 这段代码哪儿有问题,求解释。
- 使用了Spring,在一个service里使用了2个DAO ,如何配置spring?
- 请大家指点admin is not mapped [from admin where username=? and password=?]
- 文件无法检入到ClearCase,请帮忙看下是什么原因?
- weblogic9.1 上部署web,jsp 中<%@ inculde file=""%>问题
- 怎么jbpm插件老是安装不上?
- 在eclipse中调试,weblogic启动出错
- tomcat5.0+lomboz3.0+jdk1.5+eclipse3.0利用lomboz调试jsp中的问题!大哥,救命啊!
- jspsmartupload上传的问题
- 想了解EJB,望大家推薦幾本好書...
- 如何导出包含曲线图,柱状图的PPT
- 如何限制并发处理数?tomcat
这么说吧
tomcat配置了加载的bean
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/serviceBeans.xml, /WEB-INF/classes/beans.xml</param-value>
</context-param>
等tomcat启动了之后,这些bean都存在了,但是问题是我没有什么继承自servlet的类,项目里没有用到servlet这些东西。
在普通类比如,我自己写个A类,如何获取这些已经存在的bean。
如果这样new ClassPathXmlApplicationContext( "beans.xml");这些bean就是另外一些bean了。
怎么弄?还有spring的bean是单例的,单例的范围是什么,是跨线程的吗?
context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
context.getBean("xxx");
否则就自己实现BeanFactoryAware接口,Spring能自动注入Factory, 并在set方法中将该Factory放到静态变量里共享.
这么说吧
tomcat配置了加载的bean
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/serviceBeans.xml, /WEB-INF/classes/beans.xml</param-value>
</context-param>等tomcat启动了之后,这些bean都存在了,但是问题是我没有什么继承自servlet的类,项目里没有用到servlet这些东西。
在普通类比如,我自己写个A类,如何获取这些已经存在的bean。
如果这样new ClassPathXmlApplicationContext( "beans.xml");
这些bean就是另外一些bean了。
怎么弄?还有spring的bean是单例的,单例的范围是什么,是跨线程的吗?
private static ApplicationContext ac;
public static Object fetchBean(String beanName) {
try {
if (ac == null) {
return null;
}
return BeanFetcher.ac.getBean(beanName);
} catch (BeansException e) {
return null;
}
}
private BeanFetcher() {};
@Override
public void setApplicationContext(ApplicationContext ac) throws BeansException {
BeanFetcher.ac = ac;
if (ac == null) {
System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@but the ac is null");
}
System.out.println("77777777777777777777777777777"+ac.getDisplayName());
System.out.println("Has take the ac");
}
}
这个类在tomcat装载的时候ac是有值的。
但是在另外一个类里写个main函数访问,这个ac就没值了。
这是什么情况,就算不在一个线程里面,static不应该是线程共享的吗?
这不是启动另一个虚拟机了么.