Wednesday, 20 May 2015

Java Source World: How do you provide configuration metadata to the Spring Container



There are following three important methods to provide configuration metadata to the Spring Container:

  • XML based configuration file.
  • Annotation-based configuration
  • Java-based configuration

Read More »

Java Source World: What are Spring beans:



The objects that form the backbone of your application and that are managed by the Spring IoC container are called beans. A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container. These beans are created with the configuration metadata that you supply to the container, for example,
in the form of XML <bean/> definitions.


Read More »

Java Source World: What are the common implementations of the ApplicationContext



The three commonly used implementation of 'Application Context' are:

FileSystemXmlApplic ationContext: This container loads the definitions of the beans from an XML file. Here you need to provide the full path of the XML bean configuration file to the constructor.

ClassPathXmlApplicationContext: This container loads the definitions of the beans from an XML file. Here you do not need to provide the full path of the XML file but you need to set CLASSPATH properly because this container will look bean configuration XML file in CLASSPATH.

WebXmlApplic ationContext: This container loads the XML file with definitions of all beans from within a web application. 

Read More »

Monday, 11 May 2015

Java Source World: Front Controller Design Pattern

Front Controller Design Pattern | Java Source World

                                                                                                                                                    

                                                                                                                                                  Java Source World      A Java quick reference blog




 Front Controller Design Pattern:



The front controller design pattern means that all requests that come for a resource in an application will be handled by a single handler and then dispatched to the appropriate handler for that type of request. The front controller may use other helpers to achieve the dispatching mechanism.

While reading the brief overview you may have thought about ActionServlet in Struts 1 or  Dispatchers in Struts 2. Yes both of them are implementations of Front controller design pattern. But most of the developers that I have interacted to (specially the beginners) end their thought process of Front Controller at Struts only.

The Front Controller design pattern is applicable and useful for all kind of applications be it web or desktop applications and is not limited to any single programming language or framework. Before the rollout of MVC frameworks in the market, the design pattern was still in use.

The only downside was that not all application could make use of it because of the effort involved. Only the applications which had custom framework in place were using the design pattern.

So for example in case of a Java based web application, which is not using any MVC framework, all the requests would be mapped to a single servlet in web.xml file. This we know can be done by using the servlet mapping (same as we do for ActionServlet in case of Struts 1).

<web-app>
 <servlet>
 <servlet-name> FrontServlet</servlet-name>
 <servlet-class> com.example.test.FrontServlet</servlet-class>
 </servlet>
 <servlet-mapping>
 <servlet-name>FrontServlet<servlet-name>
 <url-pattern>/*</url-pattern>
 <servlet-mapping>
</servlet-mapping></servlet-name></servlet-name></servlet-mapping></web-app>



 Once the request reached the FrontServlet, it uses some configuration files to decide the appropriate dispatcher for the request and thus forwards the request using forward mechanism.


Other posts you may like to read:
Factory Pattern or Factory Method Pattern
OOPs concepts in java





                                                                                                                                                  Java Source World      A Java quick reference blog





Read More »

Thursday, 7 May 2015

Java Source World: Spring Framework - Difference between constructor and setter injection

Difference between constructor and setter injection


 There are many key differences between constructor injection and setter injection.

           Partial dependency: can be injected using setter injection but it is not possible by constructor. Suppose there are 3 properties in a class, having 3 arg constructor and setters methods. In such case, if you want to pass information for only one property, it is possible by setter method only.

           Overriding: Setter injection overrides the constructor injection. If we use both constructor and setter injection, IOC container will use the setter injection.

          Changes: We can easily change the value by setter injection. It doesn't create a new bean instance always like constructor. So setter injection is flexible than constructor injection



Read More »