解决方案 »
- struts1下载后台报clientAbortException,文件下载正确
- 关于Sqlmap中传list参数的用法!!!在线等求解!!!!
- drools的workingmemory 使用完如何释放
- 【求助】JSP问题。。。
- 框架
- 急!!!在线等 !!java split 竖线的问题
- 谁帮我写一个简单的放注入的代码嘛?
- 用MyEclipse应用gis时,必须先按gis环境吗?我已经有个现成的gis项目啦,
- HibernateTools-3.2.0.beta8使用报错!
- J2SE-->J2EE,又到了选择的路口,下一步不知道该怎么走了,请过来人指个路.先谢谢了.
- SSH事务配置问题,高手给我点指点
- Hibernate的session问题
{
this.svrSale=svrSale;
}new这个类的时候把参数传过来就行了
ApplicationContext ctx = new ClassPathXmlApplicationContext("test.xml");
ctx.getBean("Bean Name");其中test.xml要放在class路径下,或者采用全路径。
这样的代码跟tomcat就没关系了,不仅仅是web应用,即使app应用也没问题。
所以我才想用tomcat启动,只加载一次Bean的方法。
在ContextInit.java中加入new SaleWebService(svrSale);
在SaleWebService.java中加入public SaleWebService(SaleService svrSale)
{
this.svrSale=svrSale;
}
*
*/
package com.ysb.framework.listener;import javax.servlet.ServletContextEvent;import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.WebApplicationContextUtils; /**
* @author allan
*
*/
public class BeanUtil extends ContextLoaderListener { /**
* spring上下文环境
*/
private static ApplicationContext applicationContext; public void contextInitialized(ServletContextEvent event) {
super.contextInitialized(event);
applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(event.getServletContext());
} public static Object getBean(String beanName) {
return applicationContext.getBean(beanName);
}
}
将spring加载配置的监听重写一下,重写内容也很简单,继承一下ContextLoaderListener ,然后创建一个spring的静态容器,需要用到spring容器里的bean时就从静态容器里面取就行了。web.xml中的spring的加载监听改为如下。
<listener>
<listener-class>
com.ysb.framework.listener.BeanUtil
</listener-class>
</listener>
楼主的加载方式是用的servlet,其实监听和servlet都是一样,目的就是在系统启动时执行那段加载代码。
将SaleWebService和SaleService 配置成依赖关系
然后由spring容器管理他们的初始化不行么?
实在想不明白,还那么辛苦的去拿context全局对象。
out了吧,也没什么创新之处啊,spring容器也是这么拿的
别人弄好了的东西,你们硬是要去再写一次,累么?
<bean id="saleWebService" class="**.SaleWebService" abstract="true">
<property name="svrSale" ref="SaleService" />
</bean>修改类的定义@Configurable("saleWebService")
public class SaleWebService {
... public SaleService getSvrSale() {
return svrSale;
} public void setSvrSale(SaleService svrSale) {
this.svrSale = svrSale;
}
}
不过,这样会用到AOP。
当时,开发完了webservice之后,我采用static ApplicationContext basectx = new FileSystemXmlApplicationContext("file:E:/smartSaleWebservice/WebRoot/WEB-INF/applicationContext.xml");
static SaleService svrSale=(SaleService)basectx.getBean("srvSale");
的形式,获得Bean对象,但是webservice客户端连接之后,访问数据库完毕,数据库的session连接数降不下去。也就是说,每有一个客户端连一次,session会增长一些,慢慢Tomcat就爆掉了。
我不知道各位有没碰到过这样的问题。
事务的管理机制如下:<!-- 事务处理的AOP配置 -->
<bean id="ProxyTemplate" abstract="true" lazy-init="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager"><ref local="myTransactionManager" /></property>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="search*">PROPAGATION_REQUIRED</prop>
<prop key="query*">PROPAGATION_REQUIRED</prop>
<prop key="one*">PROPAGATION_REQUIRED</prop>
<prop key="isExit*">PROPAGATION_REQUIRED</prop>
<prop key="send*">PROPAGATION_REQUIRED</prop>
<prop key="get*">PROPAGATION_REQUIRED</prop>
<prop key="execute*">PROPAGATION_REQUIRED</prop>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="del*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="esave*">PROPAGATION_REQUIRED</prop>
<prop key="E_*">PROPAGATION_REQUIRED</prop>
<prop key="up*">PROPAGATION_REQUIRED</prop>
<prop key="Eup*">PROPAGATION_REQUIRED</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="dis*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="part*">PROPAGATION_REQUIRED</prop>
<prop key="eChange*">PROPAGATION_REQUIRED</prop>
<prop key="eCacle*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>但是,相同的测试类在webservice服务端进行测试,访问数据库完毕,session数量会自动降下来。
很郁闷!