`
wangzjie
  • 浏览: 72686 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

gwt+spring+hibernate的整合

    博客分类:
  • gwt
阅读更多

主要思想:在系统中读取applicationContext.xml文件,但如果放在service的方法中,每次使用该方法时都会去读该文件,则速度会慢的惊人。改进方法是把所有配置文件设置在web.xml的context参数中.

<context-param> 
<param-name>contextConfigLocation</param-name> 
<param-value> 
/WEB-INF/applicationContext-*.xml,/WEB-INF/applicationContext-*-*.xml,classpath*:applicationContext-*.xml,classpath*:applicationContext-*-*.xml 
</param-value> 
</context-param> 

<listener> 
<listener-class> 
org.springframework.web.context.ContextLoaderListener 
</listener-class> 
</listener> 

 

listener一定要有,用于初始化context参数

写个BaseService继承于RemoteServiceServlet于接口,并在init方法中写相应的读取文件方法(由于文件读取已经在context中设置好,相当于资源已经存于内存中,每次读取时速度就快很多)

public class BaseService extends RemoteServiceServlet{ 
/** 
* 
*/ 
private static final long serialVersionUID = 1L; 
protected WebApplicationContext springContext;   
  
    @Override  
    public void init(ServletConfig config) throws ServletException {   
        super.init(config);   
        springContext = WebApplicationContextUtils.getWebApplicationContext(   
                config.getServletContext());  //读取配置文件
    }   

}
gwt的server端要各实现类都要继承BaseService
public class HelloServiceImpl extends BaseService implements HelloService {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public String sayHello(int id) {
		UserManageService um = (UserManageService) springContext
				.getBean("userManageService");
		User user = um.findUserByUserID(id);
		return user.getLoginName();
	}

}
  
这里就可以使用spring端方法了
UserManageService um = (UserManageService) springContext
				.getBean("userManageService");
User user = um.findUserByUserID(id);

 具体见上传的代码(jar包是精简版的,日记有点问题,但不影响),由于只能上传10M,想要的联系我

  

分享到:
评论
9 楼 zhangquan1228 2012-12-22  
楼主能给一份吗!非常感谢,邮箱:zhangquan1228@163.com
8 楼 xuhuajian885 2012-11-16  
楼主能给一份吗!不胜感激,邮箱:xuhuajian885@163.com
7 楼 s416500624 2012-08-03  
您好!楼主,我刚开始学习GWT,希望楼主能给点GWT与其他框架集成的项目,不胜感激
邮箱:416500624@qq.com,愿大家共同进步
6 楼 liyuanchao2004 2011-11-21  
楼主,发份,谢谢,liyuanchao2004@126.com
5 楼 endison1111 2011-08-15  
正在为找不到gsh整合的资料而烦恼,感谢lz的文章,希望传一分源码给我研究研究
biding2069203@yahoo.com.cn
4 楼 willalw 2011-07-30  
楼主09年就研究得这么深入了,我刚学gwt,可以给我一个gwt-spring的例子吗?willalw@hotmail.com
3 楼 gjrzh 2011-05-05  
楼主,我正在学习gwt 可以发给我吗,gjr335@qq.com
2 楼 411912wanggang 2010-04-25  
我也想要,谢谢楼主,写的不错。我的邮箱 411912wanggang@sina.com
1 楼 seekyourcolor 2009-12-11  
大哥,我想想你学习啊,我QQ451463680,要加我啊,顺便像大哥请教下Hibernate与GWT的集成问题

相关推荐

Global site tag (gtag.js) - Google Analytics