package org.ringojs.jsgi;import org.springframework.context.ApplicationContext;import org.springframework.web.context.support.WebApplicationContextUtils;import javax.servlet.ServletConfig;import javax.servlet.ServletContext;import javax.servlet.ServletException;public class ExtJsgiServlet extends JsgiServlet {private ApplicationContext _springContext;@Overridepublic void init(ServletConfig config) throws ServletException {super.init(config);final ServletContext context = config.getServletContext();_springContext = WebApplicationContextUtils.getRequiredWebApplicationContext(context);}public ApplicationContext getSpringContext() {return _springContext;}public Object getBean(String name) {return _springContext.getBean(name);}}
<servlet><servlet-name>ringo</servlet-name><servlet-class>org.ringojs.jsgi.ExtJsgiServlet</servlet-class><init-param><param-name>optlevel</param-name><param-value>0</param-value></init-param></servlet><servlet-mapping><servlet-name>ringo</servlet-name><url-pattern>/*</url-pattern></servlet-mapping>
app.post('/profiles/:profileId', function(req, profileId) {// Get access to the servlet using the 'env' garbage dump propertyvar servlet = req.env.servlet;// Use the servlet's getBean(String) function to retrieve a configured bean from Springvar datasource = servlet.getBean('datasource');// Or maybe you are using Spring's reloadable resource bundles for externalizing your// website's localized contentvar context = servlet.getSpringContext();var welcomeMessage = context.getMessage('welcome', null, req.env.servletRequest.locale);});
I've put this on a wiki page to increase findability for (potential) users.
http://ringojs.org/wiki/Ringo_with_Spring
It's linked from "Java integration" page which is linked from "TODO"
page (which is linked from the wiki's main page), BTW.
IMHO, it would be great if more such info would be added there by you
guys actually using Ringo in according Java (enterprise) environments.
HTH,
-- Robi