java 玻璃鱼 + 弹簧
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10094473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Glassfish + Spring
提问by foFox
I have a quick question, that is, how do I run applications which use Spring framework on Glassfish server? That is, how do I make it run under control of Spring containers? Do I need to extend the server or something, I can't find much information about that, stuff I read about OSGI modules, just confused me.
我有一个简单的问题,即如何在 Glassfish 服务器上运行使用 Spring 框架的应用程序?也就是说,如何让它在 Spring 容器的控制下运行?我是否需要扩展服务器或其他什么,我找不到太多关于它的信息,我读到的关于 OSGI 模块的内容,只是让我感到困惑。
回答by Affe
Basically you use web.xml to fire up Spring with a listener and then you map one or more spring Dispatcher servlets. You define controller beans in the dispatcher-servlet.xml
, inject beans you defined in the applicationContext, and it sort of cascades down from there.
基本上,您使用 web.xml 来启动带有侦听器的 Spring,然后映射一个或多个 Spring Dispatcher servlet。您在 中定义控制器 bean dispatcher-servlet.xml
,注入在 applicationContext 中定义的 bean,然后从那里向下级联。
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
etc etc
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/myApp/*</url-pattern>
</servlet-mapping>
回答by neo
In deployment descriptor(web.xml), define Servlet Listener and context param.
在部署描述符(web.xml)中,定义 Servlet Listener 和上下文参数。
Context param - file location for spring bean files. (wild char allowed and pickup bunch of files that's under that wild char selection.)
上下文参数 - spring bean 文件的文件位置。(允许使用通配符并拾取该通配符选择下的一堆文件。)
Listener - spring class which will listen request. Different classes are available for different purpose.
侦听器 - 将侦听请求的 spring 类。不同的类可用于不同的目的。
<context-param>
<param-name>contextConfigLocation</param-name>
<!-- All file ends with Context.xml under web-inf folder -->
<param-value>WEB-INF/*Context.xml</param-value>
</context-param>
<listener>
<display-name>Spring context loader</display-name>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
<!-- use following if you want to use request scope -->
<!-- org.springframework.web.context.request.RequestContextListener -->
</listener>
<servlet>
<servlet-name>servlet name</servlet-name>
<servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>name</servlet-name>
<url-pattern>/URLName</url-pattern>
</servlet-mapping>