Featured
-
How to split a String
Below I have written a code to split a string.
by shahbaz.ahmmod -
Send Push Notification with Custom Data to iPhone device from Java Server Side
This blog will help you to send Push Notifications
by babita.dhami -
Tomcat and Eclipse Integration Error : “Unknown version of Tomcat was specified”
If you are adding Server in Eclipse for Tomcat, an
by chandan.ahluwalia -
Spring MVC and MongoDB
Repository Class Using MongoDB : Spring has th
by sumit.vyas -
How to create DLL file from java?
Hello Guy's This Blog will guide how to create D
by bhagwan.khichar
Tags
Set the JAVA_HOME Environment Variable in Windows OS
Following steps help you to set the JAVA_HOME Environment Variable in Windows OS
First check where the Java Development Kit is installed.
Usually path would be similar to one below:
C:\Program Files\Java\jdk1.6.0_10
Copy this path and...
Web applications with AnnotationConfigWebApplicationContext
Web applications with AnnotationConfigWebApplicationContext: In Spring we can use the WebApplicationInitializer in place of web.xml to initialize DispatcherServlet and use @EnableWebMvc annotation to support Spring MVC.The below example code can ...
ResourceLoaderAware in Spring framework
ResourceLoaderAware : When we load resources using bean, ResourceLoaderAware will help us to load resources using getter/setter methods.
For more details see my last blog Click
Below example will help you to understand better:
Create Cust...
ResourceLoader Interface in Spring framework
Resource loader : Spring ResourceLoader interface is used to load external data(i.e text file, media file, image file) in Spring application using the method getResource(). We can use three ways for loading resources :
URL Path :
Resource r...
Spring Validation Using Validator Interface
Validation using Spring's Validator:- In Spring we can Validate the form value or do server side validation using the validator Interface. In the Following Example Code I am using the validator interface to validate the login form.
LoginCon...
Triggering @Controller Input Validation in Spring
Triggering @Controller Input Validation:- In Spring we can enable the JSR 303 Bean Validation to put the validation on bean and validate the form value in spring MVC .
StudentController.java
package com.manish.controller;
import javax.v...
Internationalization(I18N) in Spring
Internationalization using MessageSource:- In Spring MVC we can show the LocaleResolver to achieve the Internationlization(I18N) to support the multiple language.
WelcomeController.java
package com.manish.controller;
import javax.servlet...
ApplicationContext in Spring web applications?
In this tutorial we will discuss about ApplicationContext instantiation for web applications and how to access it. There are numerous different ways to get a task done in Spring framework and that is one advantage of it.
In web application, Appl...
@Scope annotation in Spring
@Scope:- In Spring 3.0 we can define bean or we can do configuration using Java File. @Scope annotation can be used to define the bean scope.
Example:
JavaConfig.java
package com.babita;
import org.springframework.context.annotation....
How To Use ClassPathXmlApplicationContext
ClassPathXmlApplicationContext :- This can load the beans configuration file and To create and initialize all the beans inside the configuration file.you need not to provide the full path of the XML file but you have to set CLASSPATH properly be...
ApplicationContext VS BeanFactory
BeanFactory VS ApplicationContext:- The Both BeanFactory and ApplicationContext can initialize the Spring IOC Container. They Both are Java Interfaces and ApplicationContext can extends the BeanFactory. BeanFactory Inteface can only provide basic...
@Import annotation in Spring
@Import :- In Spring 3.0 we can also use the Java based Configuration instead of large XML files. We can define the bean with the help of Java files and we can also load these multiple JavaConfig file using @Import annotation in single JavaConfi...
Using context:component-scan to pick up @Configuration Classes
In Spring 3.0 using the tag context:component-scan in xml file, the entry of the class(or bean) defined under the scan tag is automatically created. The example to show use of context:component-scan tag is as below:
Example:-
JavaConfig.jav...
Instantiating the Spring container using AnnotationConfigApplicationContext
In Spring 3 we can also create a bean using java file instead of XML.It is alternate way to create the bean, you can also use xml based configuration.
HelloWorld.java
package com.babita;
public class HelloWorld {
public void p...
SPRING TYPE CONVERSION(SPI Converter)
SPI Converter
The Spring 3.0 provide the mechanism of type conversion and general Type Conversion. We have SPI to implement type conversion logic and the API that execute Type Conversion at runtime. This API can be used anywhere in Applicatio...
How to achieve Document Version Contorl in Liferay?
Liferay provides very rich environment to create versions for the Uploaded documents. You can achieve Document Version Control very easily in Liferay by using the below code.
Create the object of ServiceContext as below:
ServiceContext serv...
Spring bean Lazy-initialization
Spring container initialize all the beans registered in the bean configuration file at the time of context start up. When application starts first time all beans are initiated. This helps container to search dependencies are exist or not at the t...
Apache Tomcat Installation on Linux
In this article we will learn how to install tomcat on Linux (CentOS,Fedora and RedHat). For example we will install the tomcat 7 on CentOS operating system. Before starting tomcat installation, be sure that java should be installed on your syste...
@Bean Annotation in Spring Framework
@Bean Annotation in Spring: @Bean is used to register a bean in spring container. There are two kind of configuration we can do in Spring Framework, one is using the xml bean configuration file and second is using the java configuration file. Her...
@Configuration class-centric use of XML with @ImportResource
Configure beans using @Configuration annotation in Spring Framework :
Spring framework is a configuration base framework. In Spring Framework all configuration is done using xml files. But you know anybody can change the xml file, if change is...
How to install Java in Linux ?
In this article I will show you how to install the Java on Linux or it's version like CentOS/RedHat 7/6/5 and Fedora. There are lots of article on this top but most of them are misleading and confusing. I will show you simple steps to download an...
Load Ballancing using Redis server for caching sessions
My last post was on installing Redis server...
I found and interesting blog for practical use of Redis Server, Scaling Web applications.
Read and enjoy...
Load Balance Tomcat with Nginx and Store Sessions in Redis
For some time, I w...
IBM Bluemix is an ideal platform for building applications
IBM Bluemix is the cloud platform that helps developers rapidly build,
manage and run web and mobile applications. I found this interesting tutorial on using Bluemix.
Create a coupon-finding app by combining Yelp, Google Maps, Twitter, and
...
How to create XML File in Java using DOM parser?
To create XML file in Java,here we are using DOM parser. By using the below code you can easily create XML file.
Write the below Java class to create a XML file:
CreateXMLFile.java
package com.babita;
import java.io.File;
import jav...
How to create CSV file in java?
Sometime we need to generate CSV from data as per requirement. You can easily create CSV file by following the below steps:
Write the following Maven configuration in pom.xml file in your project:
<dependency>
<groupid>net....
Installing Redis server and running in background
Redis is an open source advance key value cache and store. It is capable of storing data structures like strings, hashes, list, sets, bitmaps and hyperloglogs.
You can download and install Redis server using the following commands
wget ht...
How to create DLL file from java?
Hello Guy's
This Blog will guide how to create DLL file from java using JNI.
Please follow the below instructions.
First create a java file that contains the native method and it loads the DLL file.
Create TestDLL.java and put below code :
...
Spring @Autowired and @Inject annotations
@Autowired and @Inject Annotations in Spring framework :
@Autowired : The power of Spring Framework is dependency injection and this dependency injection is done using the configuration file. All beans are registered in that configuration file...
Example of Annotation Based Spring Application
With Spring 2.5 it is possible to do all configuration using the annotations. We can configure all dependency injection using the annotations, so no need to define or register your bean to the xml. You can do all wiring configuration on component...
Destrction method of bean lifecyle in spring
Destruction Methods:-The destruction method of a spring bean container is called when bean is removed from the spring container.
Example:
Address.java
package com.chandan;
public class Address {
private String city;
...
Autowiring modes in spring
Autowiring modes:-Autowiring modes in spring are of 5 types:
Default, byName, byType, byConstructor and autodetect
Address.java
package com.chandan;
public class Address {
private String city;
public Address()
...
Import statement in spring
Import:- The import statement can be used to import the another bean configuration file in the existing bean configuration file.
It is used to import more than one bean configuration file from different sources.
The following example can b...
Scopes of beans in Spring
Bean Scopes:- Bean have total 5 scopes as follows:-
singleton:- It can create the single instance per Spring IoC container (default). This is default natur that single instance is stored in a cache and that instance can be stored in entire app...
Dependency resolution process in spring framework
The Spring IoC container performs bean dependency resolution :
The ApplicationContext is created and initialized with configuration metadata that describes all
the beans. Configuration metadata can be specified via XML, Java code or annotat...
ApplicationContextAware and BeanNameAware Interfaces in Spring
ApplicationContextAware Interface : Like in every web applications, we can also use application context in Spring Framework. Spring Framework provide this object in a different way. One way is that, to create new instance every time when you need...
Bean Definition Inheritance in Spring
Spring Bean Definition Inheritance: Spring Framework provides the facility of Inheritance in it's bean configuration file. Bean configuration consists lots of configuration regarding of bean like bean's id, name, class, properties etc. Spring bea...
How to load ApplicationContext in spring framwork?
ApplicationContext is an interface and it's provides configuration information to an application. Here multiple classes are provided by springframework that implements this interface and helps us to use configuration information in applications. ...
Setter-based and constructor based dependency injection in Spring
In this blog I am going to explain you about the Spring Framework implementation of the Inversion of Control (IoC), which is also known as Dependency Injection (DI). DI is a process in which objects define their dependencies and the other objects...
How to read data from CSV file in Java?
Sometimes we need to read data from a CSV file as per requirement. You can easily read the data from CSV file by following the below steps:
Write the following Maven configuration in pom.xml file in your project:
<dependency>
...
Creating Custom Scope in Spring
Using Custom Scopes, we can define new scope as well as modify the existing scope.
Custom Scope is useful for following scenarios-
creating a bean scope where beans can be shared between servlet contexts
creating a bean scope where bean...
Instantiating beans using static factory and instance factory in Spring
The benefit of using the spring framework is the masterful beans management by the IOC container. Spring framework confers options to impart the IOC container to use the factory methods for creating the instances.
Types of factory methods:
1....
Spring @Component Example
In Spring Framework normally we register all our components or beans in the XML configuration file. So when program runs spring container scan this XML file for beans and instantiate the bean components as per requirement. In the case of big proj...
Spring Bean Life Cycle: Initialization & Destruction
Spring Bean Life Cycle has two core start and end points, namely Initialization and Destruction. When bean is instantiated it require set of actions which need to performed those are set into Initialization callbacks/method and one which are requ...
How to initialize method using Spring-beans
Hello Guy's
Bellow code will help you to initialize method using Spring-beans.Here, I am using init and destroy method as attribute in bean configuration for bean to perform assigned actions upon initialization and destruction.
Follow the be...
Spring @PostConstruct and @PreDestroy
Spring Framework @PostConstruct and @PreDestroy annotations are used to just like life cycle callback methods. @PostConstruct and @PreDestroy are used widely for the process of bean initialization and to free resources at the time of bean destruc...
Life Cycle and Callback Methods in Spring Bean
Spring Framework defines some callback methods at the time of bean life cycle. These callback methods are used to perform some useful operations between the bean initialization to bean destroy. Spring provide two interface InitializingBean and Di...
Auto detect Components in Spring.
When we define the annotations @Component, @Service, @Repository, @Controller with classes, Spring automatically scan and identifies those classes and register the Bean definition with the ApplicationContext.
The @Component annotations are:
...
Spring Collections Examples
Spring supports collection framework, the list of collections Spring framework supports are List, Set, Map, and Properties. Spring allow us to inject the values at the time of bean definition in XML configuration file.
Tags used to inject coll...
Spring Inner bean
Inner beans in spring are those beans which are under the scope of another beans. In spring framework normally to inject a bean, we define it first on container with some id and pass the reference of that bean wherever dependency is needed, using...
idref Element in Spring
Spring idref Attribute : The idref is an attribute used in spring configuration. In spring, idref is used to pass the id or name of a bean as a string to other bean. Before using the idref, ensure that the bean must be defined in configuration w...