避免在我的 Action 和 Service 类中使用 applicationContext.xml
我正在使用 Struts、Spring 框架编写一个 Web 应用程序。 在 Struts Action 中,我按如下方式注入服务类
ApplicationContext context =
new ClassPathXmlApplicationContext("applicationContext.xml");
loginService = (LoginService)context.getBean("loginService");
如何避免在我的 Action 类中提及 applicationContext.xml 我只需使用 loginService = (LoginService)context.getBean("loginService");没有在我的类中指定 .xml 文件。
时发现使用了下面的内容
我在谷歌搜索private LoginService loginService = (LoginService)ApplicationContextProvider.getContext().getBean("loginService");
;但我不想使用静态方法 getContext()。
I am writing a web application using Struts, Spring framework.
In the Struts Action I am Injecting Service Classes as follows
ApplicationContext context =
new ClassPathXmlApplicationContext("applicationContext.xml");
loginService = (LoginService)context.getBean("loginService");
How can I avoid mentioning applicationContext.xml in my Action classes I just have to use
loginService = (LoginService)context.getBean("loginService"); without specifying the .xml file in my class.
I came across to use below while googling
private LoginService loginService = (LoginService)ApplicationContextProvider.getContext().getBean("loginService");
But I do not want to use static method getContext().
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Spring 支持在包中集成 Struts org.springframework.web.struts。
看一下这篇文章的示例。
Spring support Struts integration in the package org.springframework.web.struts.
Take a look at this article for an example.