Monthly Archives: November 2013

ApplicationContext or AbstractApplicationContext in Spring Framework

ApplicationContext or AbstractApplicationContext in Spring Framework

With using the ApplicationContext interface.

package com.linaittech1;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class MainApp {

    public static void main(String[] args) {
       
        ApplicationContext context = new FileSystemXmlApplicationContext (“file:/home/poganin/worksSpringer/Spring2/src/Beans.xml”);
        Mirek obj = (Mirek) context.getBean(“mirek”);
        obj.getMessage();
       
        ApplicationContext context1 = new FileSystemXmlApplicationContext (“file:/home/poganin/worksSpringer/Spring2/src/Beans.xml”);
        Lak obj1 = (Lak) context1.getBean(“lak”);
        obj1.getNum1();
        obj1.getNum2();
        obj1.getSum();
       
    }

}

With using the AbstractApplicationContext interface.

package com.linaittech1;

import org.springframework.context.AbstractApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class MainApp {

    public static void main(String[] args) {
        
        AbstractApplicationContext context = new FileSystemXmlApplicationContext (“file:/home/poganin/worksSpringer/Spring2/src/Beans.xml”);
        Mirek obj = (Mirek) context.getBean(“mirek”);
        obj.getMessage();
        context.registerShutdownHook();
        
        AbstractApplicationContext context1 = new FileSystemXmlApplicationContext (“file:/home/poganin/worksSpringer/Spring2/src/Beans.xml”);
        Lak obj1 = (Lak) context1.getBean(“lak”);
        obj1.getNum1();
        obj1.getNum2();
        obj1.getSum();
        context1.registerShutdownHook();
        
    }

}

You probably see the difference. With AbstractApplicationContext, we have a great possibility to shutdown our bean. Sometimes, it’s simply good to use the second method.

Spring Java Beans in XML Configuration File

Spring Java Beans in XML Configuration File

The XML configuration file called usually Beans.xml look in this way:

<?xml version=”1.0″ encoding=”UTF-8″?>

<beans xmlns=”http://www.springframework.org/schema/beans&#8221; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd”&gt;

</beans>

Inside, we can write many things. The most important is our beans definitions. we can do that in many ways:

A simple bean definition looks:

<bean id=”…”>

Bean configuration

</bean>

A bean definition with lazy init set on looks:

<bean id=”…” lazy-init=”true”>

Bean configuration

</bean>

A bean definition with initialization method looks:

<bean id=”…” init-method=”…”>

Bean configuration

</bean>

A bean definition with destruction method looks:

<bean id=”…” destroy-method=”…”>

Bean configuration

</bean>

So we can see some properties that are used in Beans.xml files.

class – the class of your bean

name – your bean identifier that is unique

scope – the scope of your bean objects

constructor-arg

properties

autowiring mode

lazy-initailization mode – your bean instance is created by IoC container when needed

initialization method – A callback to be called just after all necessary properties on the bean have been set by the container

destruction method – A callback to be used when the container containing the bean is destroyed

Let’s look at the scope attribute.

singleton – a single instance per Spring IoC container; it’s default

prototype – any number of object instances

Scopes connected with Spring ApplicationContext:

request

session

global-session

The example of the bean with singleton scope:

<?xml version=”1.0″ encoding=”UTF-8″?> <beans xmlns=”http://www.springframework.org/schema/beans&#8221; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd”&gt;

<bean id=”helloWorld” scope=”singleton”>
</bean>

</beans>

The example of the bean with prototype scope:

<?xml version=”1.0″ encoding=”UTF-8″?> <beans xmlns=”http://www.springframework.org/schema/beans&#8221; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd”&gt;

<bean id=”helloWorld” scope=”prototype”>
</bean>

</beans>

Life cycle of Spring bean

There are many things in the life cycle of Spring beans, but the most important are initialization and destruction. That’s why, we have init-method and destroy-method.

The initialization of our bean can be done in this way:

In Bean.xml, we have the following code:

<bean id=”mirelka” class=”com.linaittech.Mirelka” init-method=”initBean”/>

In the Mirelka.java file (our bean), we have the following code:

public class Mirelka {
public void initBean() {
our bean initialization code
}
}

The destruction of our bean can be done in this way:

In Bean.xml, we have the following code:

<bean id=”mirelka” class=”com.linaittech.Mirelka” destroy-method=”destroyBean”/>

In the Mirelka.java file (our bean), we have the following code:

public class Mirelka {
public void destroyBean() {
our bean destruction code
}
}

When we have many initialization and destruction methods, we don’t have to do it in each bean definition; we simply use this trick:

<beans xmlns=”http://www.springframework.org/schema/beans&#8221; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd&#8221; default-init-method=”initBean” default-destroy-method=”destroyBean”>
<bean id=”…”>
Bean configuration
</bean>
</beans>

We see that <beans …> </beans> include default-init-method and default-destroy-method parameters.

Second Application with Spring Framework in Eclipse IDE

Second Application with Spring Framework in Eclipse IDE

Using FileSystemXmlApplicationContext implementation of ApplicationContext Container

We prepared our Eclipse IDE for using for creating applications with Spring Framework:

How to Download and Setup Spring Framework for Eclipse IDE

Now, let’s start developing our first program. You should know that Spring technology use Java and XML. They are the most important technologies. So having created our project, create three files in src subdirectory. But Java likes packages, so we have to create one for including our files.

Right click on the src subdirectory -> New -> Package

Name your package. Remember Java convention: inverted domain name of your company. Well, it can be a false company that doesn’t exist in reality. I use

com.linaittech

Lina IT Technologies is my company. So my application’s classes will be on the path:

com.linaittech.class.java

in the Java world.

Now we can create all four files:

/src

MainApp.java

Mirek.java

Lak.java

Beans.xml

Right click on the src subdiirectory -> New -> Class -> name your class: MainApp.java -> Finish

Right click on the src subdiirectory -> New -> Class -> name your class: Mirek.java -> Finish

Right click on the src subdiirectory -> New -> Class -> name your class: Lak.java -> Finish

Right click on the src subdiirectory -> New -> Other -> write xml in Wizards -> choose XML File -> Next -> name your file: Beans.xml -> choose Create XML File from XML template -> Next -> Finish

So we have three Java files and one xml file. The XML file is the configuration file of the whole application. It join the three Java classes into one program. The structure of the program is following:

Beans.xml<—-MainApp.java

————————————————————

Mirek.java                              Lak.java

Thanks to Beans.xml, MainApp.java knows that there are two classes (Mirek.java and Lak.java) to use and what they have inside. It can be more classes in your application. They are POJO (Plain Old Java Objects). We can call all methods in them. That’s why, Beans.xml is the file with metadata. This is managed by Spring container. In this example, we use FileSystemXmlApplicationContext (one of the implementations of ApplicationContext Container). Look at MainApp.java code to see that.

The code for all our files:

Beans.xml

<?xml version=”1.0″ encoding=”UTF-8″?>

<beans xmlns=”http://www.springframework.org/schema/beans&#8221; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd”&gt;

<bean id=”mirek”>
<property name=”message” value=”Mirek jest gość!”/>
</bean>

<bean id=”lak”>
<property name=”num1″ value=”1″/>
<property name=”num2″ value=”2″/>
<property name=”sum” value=”3″/>
</bean>

</beans>

MainApp.java

package com.linaittech1;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class MainApp {

    public static void main(String[] args) {
        
        ApplicationContext context = new FileSystemXmlApplicationContext (“file:/home/poganin/worksSpringer/Spring2/src/Beans.xml”);
        Mirek obj = (Mirek) context.getBean(“mirek”);
        obj.getMessage();
        
        ApplicationContext context1 = new FileSystemXmlApplicationContext (“file:/home/poganin/worksSpringer/Spring2/src/Beans.xml”);
        Lak obj1 = (Lak) context1.getBean(“lak”);
        obj1.getNum1();
        obj1.getNum2();
        obj1.getSum();
        
    }

}

Mirek.java

package com.linaittech;

public class Mirek {
    
   private String message;
    
    public void setMessage(String message){
        this.message = message;
        }
    public void getMessage(){
        System.out.println(“Your Important Message : ” + message);
        }

}

Lak.java

package com.linaittech;

public class Lak {
    private int num1;
    private int num2;
    private int sum;
    
    public void getNum1() {
        System.out.println(“The num1 is : ” + num1);
    }
    public void setNum1(int num1) {
        this.num1 = num1;
    }
    public void getNum2() {
        System.out.println(“The num2 is : ” + num2);
    }
    public void setNum2(int num2) {
        this.num2 = num2;
    }
    public void getSum() {
        System.out.println(“The sum is : ” + sum);
    }
    public void setSum(int sum) {
        this.sum = num1 + num2;
    }

}

You don’t have to start a server because so far we aren’t going to display nothing on web. Just run the application in Eclipse: Run -> Run or use Ctrl + F11.

If you run your application in Eclipse IDE, you will get in Console:

lis 29, 2013 1:59:55 PM org.springframework.context.support.FileSystemXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.FileSystemXmlApplicationContext@1b24628: startup date [Fri Nov 29 13:59:55 CET 2013]; root of context hierarchy
lis 29, 2013 1:59:55 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from URL [file:/home/poganin/worksSpringer/Spring2/src/Beans.xml]
lis 29, 2013 1:59:56 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@50abcc: defining beans [mirek,lak]; root of factory hierarchy
Your Important Message : Mirek jest gość!
lis 29, 2013 1:59:56 PM org.springframework.context.support.FileSystemXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.FileSystemXmlApplicationContext@774f6e: startup date [Fri Nov 29 13:59:56 CET 2013]; root of context hierarchy
lis 29, 2013 1:59:56 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from URL [file:/home/poganin/worksSpringer/Spring2/src/Beans.xml]
lis 29, 2013 1:59:56 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@eed1b8: defining beans [mirek,lak]; root of factory hierarchy
The num1 is : 1
The num2 is : 2
The sum is : 3

That’s all! Our output is everything what is in red. The rest is just information for you to know  what has happened step by step. You see that there are two outputs from two subclasses (Mirek.java and Lak.java).

You see that the out is the same as in

First Application with Spring Framework in Eclipse IDE

Using ClassPathXmlApplicationContext implementation of ApplicationContext Container

two subclasses (Mirek.java, Lak.java, and Beans.xml) are the same in both cases, but MainApp.java is different.

Warning:

Be careful. Eclipse IDE has many bugs that can lead you astray. When you working with FileSystemXmlApplicationContext, be sure that you’ve fixed “missing libraries” error before running your application. You should check before every code changing. Go to details at:

JAR Libraries Missing in Order and Export Tab in Eclipse IDE

JAR Libraries Missing in Order and Export Tab in Eclipse IDE

If not, the running of your project can fail in spite of good code without errors.

JAR Libraries Missing in Order and Export Tab in Eclipse IDE

 JAR Libraries Missing in Order and Export Tab in Eclipse IDE

You can get an error in Eclipse IDE:

Error:   Could not find or load main class...

And your application doesn’t run. So go to the Window -> Show View -> Problems

The Problems tab appears. You can see all warnings and errors that prevents your application from running. And you should see that some jar libraries is missing.

Well, what to do to fix that?

Right click on your project name -> Build Path -> Configure Build Path -> Order and Export tab

Check if some of these libraries are missing. You should see the word “missing” at the end of the entries. If so, go to Libraries tab -> Select all external libraries (for example, I have common-logging libraries and spring framework libraries) -> click Remove button to delete them ( do not remove JRE System Library!)

Now, export all these external libraries another time.

Click Add External JARs -> search your libraries (common-logging libraries and spring framework libraries in my project) on your HDD to export them another time -> OK

Back to Order and Export Tab -> you should see the exported libraries without “missing” at the end of the entries -> OK

Try to run your project.

Spring Inversion of Control Containers

Spring Inversion of Control Containers

Spring Container is the most important module in Spring Framework. It manages the files that are included in your application and their objects. These objects are called Java Beans.

Spring Container uses:

– Metadata: a XML configuration file, Java annotations, or Java code

– POJO Classes: Java classes

to make your application.

There are two Spring Containers:

BeanFactory (an org.springframework.beans.factory.BeanFactory interface) – simpler. light-weight applications, mobile, the most important implementation is XmlBeanFactory class

ApplicationContext (an org.springframework.context.ApplicationContextinterface interface) – more complicated, enterprise-oriented, heavy-weight applications, not-mobile, generally recommended to use, the most important implementation are FileSystemXmlApplicationContext, ClassPathXmlApplicationContext, and WebXmlApplicationContext

BeanFactory container is included in ApplicationContext container.

First Application with Spring Framework in Eclipse IDE

First Application with Spring Framework in Eclipse IDE

Using ClassPathXmlApplicationContext implementation of ApplicationContext Container

We prepared our Eclipse IDE for using for creating applications with Spring Framework:

How to Download and Setup Spring Framework for Eclipse IDE

Now, let’s start developing our first program. You should know that Spring technology use Java and XML. They are the most important technologies. So having created our project, create three files in src subdirectory. But Java likes packages, so we have to create one for including our files.

Right click on the src subdirectory -> New -> Package

Name your package. Remember Java convention: inverted domain name of your company. Well, it can be a false company that doesn’t exist in reality. I use

com.linaittech

Lina IT Technologies is my company. So my application’s classes will be on the path:

com.linaittech.class.java

in the Java world.

Now we can create all four files:

/src

MainApp.java

Mirek.java

Lak.java

Beans.xml

Right click on the src subdiirectory -> New -> Class -> name your class: MainApp.java -> Finish

Right click on the src subdiirectory -> New -> Class -> name your class: Mirek.java -> Finish

Right click on the src subdiirectory -> New -> Class -> name your class: Lak.java -> Finish

Right click on the src subdiirectory -> New -> Other -> write xml in Wizards -> choose XML File -> Next -> name your file: Beans.xml -> choose Create XML File from XML template -> Next -> Finish

So we have three Java files and one xml file. The XML file is the configuration file of the whole application. It join the three Java classes into one program. The structure of the program is following:

Beans.xml<—-MainApp.java

————————————————————

Mirek.java                              Lak.java

Thanks to Beans.xml, MainApp.java knows that there are two classes (Mirek.java and Lak.java) to use and what they have inside. It can be more classes in your application. They are POJO (Plain Old Java Objects). We can call all methods in them. That’s why, Beans.xml is the file with metadata. This is managed by Spring container. In this example, we use ClassPathXmlApplicationContext (one of the implementations of ApplicationContext Container). Look at MainApp.java code to see that.

The code for all our files:

Beans.xml

<?xml version=”1.0″ encoding=”UTF-8″?>

<beans xmlns=”http://www.springframework.org/schema/beans&#8221; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd”&gt;

<bean id=”mirek” class=”com.linaittech.Mirek”>
<property name=”message” value=”Mirek jest gość!”/>
</bean>

<bean id=”lak” class=”com.linaittech.Lak”>
<property name=”num1″ value=”1″/>
<property name=”num2″ value=”2″/>
<property name=”sum” value=”3″/>
</bean>

</beans>

MainApp.java

package com.linaittech;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainApp {

    public static void main(String[] args) {
        
        ApplicationContext context = new ClassPathXmlApplicationContext(“Beans.xml”);
        Mirek obj = (Mirek) context.getBean(“mirek”);
        obj.getMessage();
        
        ApplicationContext context1 = new ClassPathXmlApplicationContext(“Beans.xml”);
        Lak obj1 = (Lak) context1.getBean(“lak”);
        obj1.getNum1();
        obj1.getNum2();
        obj1.getSum();
    }

}

Mirek.java

package com.linaittech;

public class Mirek {
    
   private String message;
    
    public void setMessage(String message){
        this.message = message;
        }
    public void getMessage(){
        System.out.println(“Your Important Message : ” + message);
        }

}

Lak.java

package com.linaittech;

public class Lak {
    private int num1;
    private int num2;
    private int sum;
    
    public void getNum1() {
        System.out.println(“The num1 is : ” + num1);
    }
    public void setNum1(int num1) {
        this.num1 = num1;
    }
    public void getNum2() {
        System.out.println(“The num2 is : ” + num2);
    }
    public void setNum2(int num2) {
        this.num2 = num2;
    }
    public void getSum() {
        System.out.println(“The sum is : ” + sum);
    }
    public void setSum(int sum) {
        this.sum = num1 + num2;
    }

}

You don’t have to start a server because so far we aren’t going to display nothing on web. Just run the application in Eclipse: Run -> Run or use Ctrl + F11.

If you run your application in Eclipse IDE, you will get in Console:

lis 28, 2013 12:51:13 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@b1a0f9: startup date [Thu Nov 28 12:51:12 CET 2013]; root of context hierarchy
lis 28, 2013 12:51:13 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [Beans.xml]
lis 28, 2013 12:51:14 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@10737c8: defining beans [mirek,lak]; root of factory hierarchy
Your Important Message : Mirek jest gość!
lis 28, 2013 12:51:14 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@e3e421: startup date [Thu Nov 28 12:51:14 CET 2013]; root of context hierarchy
lis 28, 2013 12:51:14 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [Beans.xml]
lis 28, 2013 12:51:15 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@190a6db: defining beans [mirek,lak]; root of factory hierarchy
The num1 is : 1
The num2 is : 2
The sum is : 3
That’s all! Our output is everything what is in red. The rest is just information for you to know  what has happened step by step. You see that there are two outputs from two subclasses (Mirek.java and Lak.java).

My pom.xml Configuration File in a Spring Project

My pom.xml Configuration File in a Spring Project

POM is Project Object Model; it’s a XML configuration file of Maven 2 that uses the information included here to build our project. That’s why it’s very important to know something about it.

<?xml version=”1.0″ encoding=”UTF-8″?>

<project xmlns=”http://maven.apache.org/POM/4.0.0&#8243; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd”&gt;

<modelVersion>4.0.0</modelVersion>

<groupId>com.linaittech</groupId>

<artifactId>wik</artifactId>

<name>Faka</name>

<version>1.0.0-BUILD-SNAPSHOT</version>

<properties>

<java-version>1.6</java-version>
<org.springframework-version>3.1.1.RELEASE</org.springframework-version>
<org.aspectj-version>1.6.10</org.aspectj-version>
<org.slf4j-version>1.6.6</org.slf4j-version>

</properties>

<dependencies>

<!– Spring –>

<dependency>

<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<!– Exclude Commons Logging in favor of SLF4j –>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>

<!– AspectJ –>

<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>

<!– Logging –>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
<scope>runtime</scope>
</dependency>

<!– @Inject –>

<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>

<!– Servlet –>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>

<!– Test –>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>

<plugins>

<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>org.test.int1.Main</mainClass>
</configuration>
</plugin>

</plugins>

</build>

<packaging>war</packaging>

</project>

It’s a typical XML syntax. In general, there are all properties, dependencies and plugins needed to build your project. In other words, your files and libraries. Thanks to that, Maven knows how and what to build. This is like a glue that join all the components in one web application.

The most important information about your project:

<modelVersion>4.0.0</modelVersion> – POM version

<groupId>com.linaittech</groupId> – the name of your package

<artifactId>wik</artifactId> – context in your project

<name>Faka</name> – the name of your project

<version>1.0.0-BUILD-SNAPSHOT</version> – used for projects under active development (your project probably isn’t) to know exactly what and when

Among properties, you can see:

– All information about the fundamental components that are included in your project: Java EE version, Spring Framework version, Aspect-oriented Java extension version, Simple Logging Facade for Java

Among dependencies, you can see:

– Core Spring libraries – taken from spring-context

– Aspect Oriented Programming – taken from aspectjrt

– Logging – we use slf4j-api, jcl-over-slf4j, slf4j-log4j12, log4j

– Injection – we use javax.inject

– Servlet management – all the APIs that are needed for servlets: servlet-api, jsp-api, jstl

– Testing – we use JUnit, version 4.7, during test only

Among plugins used for building your project, you can see:

– Maven 2 plugins for Eclipse IDE – maven-eclipse-plugin, maven-compiler-plugin, exec-maven-plugin

These tags are used for excluding:

<exclusions>
<!– something –>
<exclusion>

 

How to Download and Setup Spring Framework for Eclipse IDE

How to Download and Setup Spring Framework for Eclipse IDE

To download Spring Framework, go to the link:

http://repo.spring.io/release/org/springframework/spring/

Search the most recent version. At the time of writing this article, it’s

3.2.5.RELEASE/            06-Nov-2013 19:50    -

Click it, and you see some items. Choose the first one:

spring-framework-3.2.5.RELEASE-dist.zip             06-Nov-2013 19:51  48.05 MB

Click to download the libraries in zip archive. Unzip it. Note that I use Linux but there’s no difference for you.

You should get into the main directory of Spring Framework, and then into libs one. There are jar archives you need for Eclipse.

Ok. Open Eclipse.

Create a new Java project: File -> New -> Java Project (or click Other… if you don’t see this item) -> Choose your Project Name -> Next -> Finish

Now you see your project in Eclipse (in Package Explorer on the left).

Right click the project -> Build Path -> Configure Build Path

Click Libraries Tab -> Click Add External JARs -> Search your main Spring Framework directory, then libs one -> Highlight all libraries (jars) -> OK

You see the libraries you will add to your project -> OK

You have the Spring libraries added to your other libraries in your project.

It’s not all you need. You should download commons-logging from:

http://commons.apache.org/proper/commons-logging/download_logging.cgi

Unpack it to have the directory with libraries.

Right click the project -> Build Path -> Configure Build Path

Click Libraries Tab -> Click Add External JARs -> Search your main commons-logging directory -> Highlight all libraries (jars) -> OK

You see the libraries you will add to your project -> OK

Now you have all what you need to build Spring applications in  Eclipse.

Go with coding!

Warning:

There’s some error in Eclipse IDE when you try running your application. If you run your application with open xml configuration file (usually Beans.xml, but the name can be  different – it depends on you which name you chose), you will get a strange error in console. It’s a false error. To avoid it, just don’t start you application at Bean.xml file opened. It can be started on other file opened, for example the main class of your project. Try it out.

Upgrading openSuse 12.2 to 13.1

Upgrading openSuse 12.2 to 13.1

The new version of openSuse has been recently released . There are many new things you should be interested in. I’m exploring them. Especially, I’m amazed at the computer graphics of the new operating system. Even Unity3D runs on openSuse 13.1 perfectly. So I wish to tell you how to upgrade openSuse to 13.1. You probably have 12.2 or 12.3 version installed on your computer. There is no difference in upgrading to 13.1 version.

1/ Go to the official openSuse website

2/ Go to Downloads

3/ Choose your version and the way of downloading: I downloaded openSUSE-13.1-DVD-1586.iso to burn it on a DVD disk

4/When the ISO image is downloaded on your computer, run K3B, a KDE tool for burning files or ISO images.

5/Tools -> choose burning ISO images

6/Choose the ISO image you wish to burn

7/Wait until K3B check the md5

8/Check if the checksum of your ISO image is the same as on the website is

9/Insert your empty DVD disk

10/All settings should be default, but you can tick verifying data on the burnt disk. It’s good to know that your operating system is without errors.

11/Consider the speed of recording. Lower speed is safer, for example 4x, but you probably have modern hardware, so you should use 8x at least. To be sure if your settings are good, and you can burn with no errors, just use the Simulation function in K3B. It will be running without using a laser and no data will be recorded on your DVD disk. Just tick Simulation and click Start. You will see how your burning will be working. If the simulation will be finished with success, you can start a real burning. Just read all messages in K3B.

12/OK. If you set all, just click Start to burn the ISO image.

13/Wait patiently for the end of burning. Then, K3B will be verifying the DVD disk. When the verification will be successful, your disk is ready to use.

14/There should not be any unpleasant surprises for you during upgrading process, but better make the backup of your files. Just in case.

15/To start to upgrade, just reboot your operating system with the burnt DVD disk inserted in the driver. Sometimes, there’s no booting to the disk, so you are forced to check BIOS settings. Be sure CD/DVD is the first booting device in your BIOS settings.

16/After having booted to the DVD disk you burnt, go with instructions you see on the monitor (for more details, go to http://activedoc.opensuse.org/book/opensuse-start-up/chapter-1-installation-quick-start).

17/When you see the Installation Mode screen, just select Update an Existing System, not New Installation that is default (don’t forget that!).

18/Go with instructions you see on the monitor. Default settings should be the best for you.

19/Check the Installation settings – you can abort the upgrading here with no changes on your computer

20/If you are ready to upgrade, just click Install.

21/Watch the installation process – many packages will be installed and some removed from your operating system. Wait until the end of upgrading. It can last some time. be patient. Do not interrupt the upgrading process because it will break your system.

22/Soon, you will be booted to the new operating system that is openSuse 13.1. The old configuration of your previous operating system (12.2 or 12.3) should be unchanged. Check if everything works. If not, you are forced to fix manually. However, I think there won’t be any problems with upgrading.

23/Enjoy your new operating system, openSuse 13.1! You won’t come back to Windows any more.