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.
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.
<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>
In deployment descriptor(web.xml), define Servlet Listener and context param.
Context param - file location for spring bean files. (wild char allowed and pickup bunch of files that's under that wild char selection.)
Listener - spring class which will listen request. Different classes are available for different purpose.
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With