|
|||||
|
|||||
Web Integration
Yan container can be used within a web application. ConfigurationIn order for the Nuts xml configuration file to be picked up by the servlet container, one has to edit the web.xml file to include the following entry:
That's all for the configuration. Use Yan container in servlet.Then, within any servlet, you can retrieve the jfun.yan.Container object from the ServletContext as such: Container yan = (Container)servletContext.getAttribute("jfun.yan.Container");
This ServletContext instance is also automatically registered in the container if there's no component of type ServletContext already registered in the container. The key is typically "servletContext". If there's already a component registered under this key, the ServletContext class is used as the key. Another feature of the web integration is that, components with a property setter "setServletContext(ServletContext context)" will be auto-magically injected with the ServletContext object. There's no proprietary interface like "ServletContextAware" to implement. Thus the component has no dependency on the infrastructure. (Well, it has to depend on ServletContext) This property setter name can be specified explicitly using the "servlet-context-property" attribute in the configuration file such that: <bean id="mycomponent" ... servlet-context-property="servletContextInstance"/> Thus, the "mycomponent" class can define a "setServletContextInstance(ServletContext context)" instead. Note, if this "setServletContext" property is involved in wiring either explicitly (by manual wiring or "property-names") or implicitly (by using "autowire"), the wiring overrides the auto-magic injection. Extending containerIt is sometimes desirable to register custom services, custom autowire modes or custom tags at startup, so that one can use these tags and autowire modes in the nuts configuration file. This can be done by subclassing YanLoaderListener and YanLoader. Since YanLoaderListener's only responsibility is to delegate to YanLoader, the subclass of YanLoaderListener just needs to create a different YanLoader object. The subclass of YanLoader class does the actual customization. Please refer to the API documentation for detailed information. |
|||||
|
Copyright 2003-2006 - The Codehaus. All rights reserved unless otherwise noted.
Powered by Atlassian Confluence
|
|||||