Spring MVC 4 Autowire Example
Spring MVC 4 Autowire Example shows a real time implementation of autowiring a bean to required service.
Spring @Autowired annotation is used for autowiring a bean to constructor, setter method, property or methods.
Following are the different ways we can do autowire feature
- Auto-Wiring "no" -> This is default mode means no autowiring
- Auto-Wiring "byName" -> This means autowiring happens using the matching property name
- Auto-Wiring "byType" -> This means autowiring happens using the matching type
- Auto-Wiring "constructor" -> This means autowiring happens through constructor according to the exact arguments
Spring MVC 4 REST Example
Spring MVC 4 REST Example explains about creating a simple Spring MVC REST service using eclipse.
In this example we are using Jackson JSON API for returning JSON response according to the request
Now a days more and more deployment is going based on restful services compare to WSDL Webservices, due to the weights towards the simplicity of configuration
You can see the below example, which is demonstrating How to create a Spring Restful service using MVC 4
Spring MVC 4 Example
Spring MVC 4 Example explains step by step example of configuring Spring MVC with eclipse
Spring version 4.0 provides full support for the latest Java 8 features.
Spring MVC is a popular Java Model-View-Contraller (MVC) framework. Basically spring is request based framework, which revolve around DispatcherServlet that dispatches the requests with the help of different lifecycle interfaces
Spring MVC have following important interfaces to handle a request during the execution phases of a HTTP request.
- HandlerMapping
- HandlerAdapter
- Controller
- View
- ViewResolver
- HandlerInterceptor
- LocaleResolver
- MultipartResolver
Asynchronous Web Service Using CXF
Asynchronous Web Service Using CXF explains about Creating / Developing JAX-WS Asynchronous Web service with the help of Apache CXF, Spring, Eclipse and deployed in Tomcat
In this example we are showing implementing an Asynchronous SOAP services using CXF Java first approach.
The asynchronous model allows the client thread to continue after making a two-way invocation without being blocked while awaiting a response from the server. Once the response is available, it is delivered to the client application asynchronously
For this there are two alternative approaches:
1) Callback: client application implements the javax.xml.ws.AsyncHandler interface to accept notification of the response availability
2) Polling: client application periodically polls a javax.xml.ws.Response instance to check if the response is available
Reference -> http://cxf.apache.org/docs/developing-a-consumer.html
CXF Asynchronous Client
CXF Asynchronous Client tells about creating a SOAP/WSDL asynchronous client using Apache CXF WebService Framework
There are two options available for receiving data through asynchronous calls from client with CXF.
1) Polling: the client application periodically polls a javax.xml.ws.Response instance to check if the response is available
2) Callback: the client application implements the javax.xml.ws.AsyncHandler interface to accept notification of the response availability
Reference -> http://cxf.apache.org/docs/developing-a-consumer.html
Below we are showing examples for both approaches
JSTL If Else Example
JSTL If Else Example explains about testing different conditions as per the requirements. It also provides a secondary path (else case) of execution, when an "if" conditions become false.
We have already seen the usage of JSTL If Example
How to use if-else option in JSTL?
There are 2 ways, we can achieve if-else statements using JSTL
1) You can use JSTL C:Choose C:When C:Otherwise Tag
2) You can use JSTL Mod (modulus) operator
You can see the below example, which is demonstrating JSTL If Else Example Using Mod operator
Apache DBUtils Tutorial
The Apache Commons DbUtils library is a small set of classes designed to make working with JDBC easier. JDBC resource cleanup code is mundane, error prone work so these classes abstract out all of the cleanup tasks from your code leaving you with what you really wanted to do with JDBC in the first place: query and update data.
Some of the advantages of using DbUtils are:
No possibility for resource leaks. Correct JDBC coding isn't difficult but it is time-consuming and tedious. This often leads to connection leaks that may be difficult to track down.
Cleaner, clearer persistence code. The amount of code needed to persist data in a database is drastically reduced. The remaining code clearly expresses your intention without being cluttered with resource cleanup.
Automatically populate JavaBean properties from ResultSets. You don't need to manually copy column values into bean instances by calling setter methods. Each row of the ResultSet can be represented by one fully populated bean instance.
We can also use Connection Pool(Datasource) with DBUtils, it is good practice to use a connection pool in your applications in order to increase the performance and scalability
DBUtils simplifies the CRUD (Create,Retrieve,Update,Delete) operations, with any database.
DbUtils is designed to be:
Small - you should be able to understand the whole package in a short amount of time.
Transparent - DbUtils doesn't do any magic behind the scenes. You give it a query, it executes it and cleans up for you.
Fast - You don't need to create a million temporary objects to work with DbUtils.
Referenece - > http://commons.apache.org/proper/commons-dbutils/
JSTL c:url Example With c:param Tag
JSTL <c:url> tag is used for storing a url into a variable with proper url rewriting, mostly <c:url> is used with <c:param> tag for adding parameter inside a <c:url>.
You can see required attributes for <c:url> and <c:param> tags on the below example.
<c:url> With Request scope
<c:url var="url" value="/index.jsp" context="/JSTLExample" scope="request"/>
${requestScope.url}
<c:url> With Session scope
<c:url var="url" value="/index.jsp" context="/JSTLExample" scope="session"/>
${sessionScope.url}