Skip to main content

ApplicationContext and WebApplicationContext

In non-Web Applications, ApplicationContext  is a Interface to provide bean configurations to our applications from XML files.  ApplicationContext has two Implementations which are
          1. FileSystemXmlApplicationContext
          2. ClassPathXmlApplicationContext

FileSystemXmlApplicationContext can access all your system files.It requires absolute path of your file.
ApplicationContext ctx = new FileSystemXmlApplicationContext("c:/bean.xml");

ClassPathXmlApplicationContext can access all files placed in CLASSPATH or in .jar.It requires its file name only  to access.
ApplicationContext ctx = new ClassPathXmlApplicationContext("bean.xml");

Then what is to do when application in Web Application?

All application having web.xml are Web Application.No Sceptice about it or have?
WebApplication has two hierarchies
         1. Root Context
         2. Each Servlet Spacific Contexct

Each servlet has its own application contexts with mappings,handlers,namespace....
But Root context is loaded by ContextLoaderListner and it is shared by all other specific contexts.You can say like a global.If want to declare global param,then declare them in root context and automatically will available in other contexts.
Both context are represented by WebApplicationContext interface.
Of course, WebApplicationContext extends ApplicationContext (extends in functionality not programming extend ) with extra feature that are required for Web-Application.

How you can get that context?

ApplicationContext and BeaFactoty are available in web application. BeanFactory has scope limited to beans and having functionality related to beans. ApplicationContext has functionality of beans as well as other functionalities present in servlet respective to bean.
BeanFactory is subset of ApplicationContext.
Same is the case applicable for ApplicationContextAwar  interface and BeanFactoryAware interface  which are required to get respective context.

WebApplicationContextUtils is available in spring web application to get web application context.


Popular posts from this blog

Share data between Iframe and its Parent using JQuery

There could be requirement that you have to pass variables values to Iframe from parent or in other scenario you have to pass values from Iframe to its parent.I am going to show simple example of above situation with the help of JQuery.
           Support we have parent HTML page having iframe included like below

<html> <body> <input id="parentValue" type="text" value="I am from Parent !" /> <iframe src="domainurl/relativepath" id="iframe"></iframe> <script> $(document).ready(function() { //code to take value from child iframe var childValue = $("#iframe").contents().find("#childValue").val(); alert(childValue); }); </script> </body> </html> 
        and we have frame code like below
<html> <body> <input id="childValue" type="text" value="I …

Spring Default Limit for Collection and Array is 256

If you are working in Web Application Development then you may stuck or already had ,then you will get mad of getting this error

How this error emanates in Spring?

i will explain you with example.Suppose you are adding Values in List in JSP using JSTL tag or other.
This list is in Form(HTML).When you POST this form,In behind Stage,Spring does binding of Object and List if present.

But wait...
In Spring,Default limit for array and collection growing is 256.

Why this limit is Set?

seldom you have to send List size greater than this limit.
Spring has set this limit to avoid notable OutOfMemoryErrors in case of large indexes.

So,than What if i want to set Collection greater than this size?

I had told earlier,spring does binding behind.If we tell spring to increase it's size or set collection size behalf of spring.
You you can do it.

We have initBinder,  in Spring  it is called when spring does the binding mechanism
e.g @Mod…

Apache FOP Tutorial for PDF Generation

What is meant by Apache FOP?

Apache is providing open source JAVA application for PDF(or any other format) file generation from XML data.Simply to can give data in XML,it gives output in PDF or any format.But it is primary for PDF output.

Official explanation,
OP (Formatting Objects Processor) is the world's first print formatter driven by XSL formatting objects (XSL-FO) and the world's first output independent formatter. It is a Java application that reads a formatting object (FO) tree and renders the resulting pages to a specified output. Output formats currently supported include PDF, PCL, PS, SVG, XML (area tree representation), Print, AWT, MIF and TXT

How wcan configure apache fop with our project?

I am going to explain how to generate PDF using Apache FOP.
I will explain it in steps

Step 1:
You will require 3 jar for configurations.Here fop jar depend on both avalon api and avalon impl.
              1.    apache fop 1.1
              2.    avalon-framework-api 4.3.1