Steps to integrate Spring and Maven

Spring and Maven

Spring Siri - Belajar integrasi Maven Melalui Teladan,,en,Dalam artikel ini kita akan bekerja pada integrasi Maven dengan rangka kerja Spring,,en,Kami akan menjelaskan semua komponen dan bagaimana ia boleh dilaksanakan dengan menggunakan contoh-contoh kod bekerja,,en,Maven adalah sangat popular pada masa kini untuk projek-projek bangunan dengan cara yang bersih,,en,Maksud perkataan ',,en,MAVEN ',,en,adalah ',,en,Accumulator pengetahuan,,en,Kelebihan utama maven adalah untuk mengendalikan proses pembinaan dengan cara yang mudah dan ia menjadikan keseluruhan proses lebih terkawal berbanding skrip semut,,en,Berikut adalah contoh mudah maven dan musim bunga integrasi,,en,Komponen pertama ialah SpringMaven.java kelas java yang mengandungi mesej yang mudah,,en

Tinjauan

In this article we are going to work on Maven integration with Spring framework. As in the earlier Spring series, we are going to directly jump into the coding part to explore the implementation. We will explain all the components and how they can be implemented by using working code examples.

Maven is very popular nowadays for building projects in a clean way. The meaning of the word ‘MAVEN’ is ‘Accumulator of knowledge’. The main advantage of maven is to handle building process in an easy way and it makes the entire process more manageable compared to ant script.







Following is a simple example of maven and spring integration.

  • The first component is a java class SpringMaven.java which contains a simple message.

package com.techalpine;

SpringMaven kelas awam,,en,Hello Maven,,en,Komponen kedua ialah,,en,fail yang digunakan oleh maven untuk menentukan kebergantungan dan butiran lain,,en,Kita akan menambah sedikit ke fail ini supaya kita boleh menjalankan aplikasi kami walaupun maven,,en,membina,,en,plugin,,en,org.codehaus.mojo,,en,exec-maven-plugin,,en,hukuman mati,,en,pelaksanaan,,en,matlamat,,en,mainClass,,en,com.techalpine.SpringMaven,,en,sekarang,,en,langkah adalah untuk menyusun kod dengan menggunakan arahan ',,en,MVN menyusun,,en,Ia akan memaparkan sesuatu output seperti ini,,en,Mengimbas untuk projek-projek,,en,selesai pada,,en,Fri Sep,,en,BST,,en,Memory Final,,en,M / 12M,,en,MVN exec,,en,exec,,en,Berikut adalah pengubahsuaian fail pom.xml untuk mengintegrasikan rangka kerja musim bunga,,en,org.springframework,,en,Kelas berikut telah dicipta untuk menguji integrasi spring dengan maven,,en,Ini merupakan satu lagi kelas java mudah untuk mencetak messge yang,,en,helloMaven kelas awam,,en,Salam kepada kekosongan awam,,en

{

awam statik tidak sah utama( Rentetan[] args )

{

System.out.println( “Hello Maven!” );

}

}

  • The second component is xml file used by maven to specify dependencies and other details. We’re going to add a little bit to this file so that we can easily run our application though maven.

<projek

<build>

<plugins>

<plugin>

<groupId>org.codehaus.mojo</groupId>

<artifactId>exec-maven-plugin</artifactId>

<executions>

<execution>

<goals>

<goal>java</goal>

</goals>

</execution>

</executions>

<konfigurasi>

<mainClass>com.techalpine.SpringMaven</mainClass>

</konfigurasi>

</plugin>

</plugins>

</build>

</projek

  • Now the 3rd step is to compile the code by using the command ‘mvn compile’. It will display an output something like this.

$ mvn compile

[INFO] Scanning for projects…

[INFO] ————————————————————————

[INFO] BUILD SUCCESSFUL

[INFO] ————————————————————————

[INFO] Total time: 1 second

[INFO] Finished at: Fri Sep 05 19:50:45 BST 2008

[INFO] Final Memory: 5M/12M

[INFO] ————————————————————————

$ mvn exec:java

[INFO] [exec:java]

Hello Maven







  • The following is a modification of pom.xml file to integrate the spring framework.

<dependencies>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring</artifactId>

<version>2.5.5</version>

</dependency>

</dependencies

  • The following class has been created to test the integration of spring with maven. This is another simple java class to print a messge.

package com.techalpine;

public class helloMaven

{

private String name;

public void setName(String name)

{

this.name = name;

}

public String getName()

{

return name;

}

public void greet()

{

System.out.println(“Hello ” + getName());

}

}

  • Berikut adalah fail konfigurasi xml,,en,rangka kerja spring,,en,kacang DOCTYPE AWAM,,en,SPRING // DTD BEAN // EN,,da,www.springframework.org/dtd/spring-beans.dtd,,en,com.techalpine.helloMaven,,vi,Berikut adalah kelas java untuk menguji integrasi spring maven,,en,import com.techalpine.helloMaven,,vi,import org.springframework.core.io.ClassPathResource,,en,SpringMavenTest kelas awam,,en,ClassPathResource baru,,en,spring_maven.xml,,en,helloMaven hello =,,en,helloMaven,,vi,hello.greet,,en,Sekarang jika anda membina dan menjalankan permohonan itu ia akan memaparkan output berikut,,en,Artikel ini adalah terutamanya untuk pemaju yang mahu mencuba sesuatu yang hands-on,,en,Kami telah mengasingkan beberapa bahagian teori dengan tekanan yang lebih pada bahagian pengekodan,,en (xml) for spring framework.

<?short xml =”1.0″ pengekodan =”UTF-8″?>

<!DOCTYPE beans PUBLIC “-//SPRING//DTD BEAN//EN”

“http://www.springframework.org/dtd/spring-beans.dtd”>

<beans>

<bean id=”hello” class=”com.techalpine.helloMaven”>

<nama harta =”nama” value =”TechAlpine” />

</bean>

</beans

  • Following is the java class to test the spring maven integration.

package com.techalpine;

import com.techalpine.helloMaven;

import org.springframework.core.io.ClassPathResource;

import org.springframework.beans.factory.BeanFactory;

import org.springframework.beans.factory.xml.XmlBeanFactory;

public class SpringMavenTest

{

awam statik tidak sah utama( Rentetan[] args )

{

BeanFactory factory = new XmlBeanFactory(

new ClassPathResource(“spring_maven.xml”));

helloMaven hello = (helloMaven) factory.getBean(“hello”);

hello.greet();

}

}

Now if you build and run the application it will display the following output.

Hello TechAlpine

Kesimpulan

This article is mainly for the developers who wants to try things hands-on. We have kept some theoretical part with more stress on the coding part. Tumpuan kepada siri Spring ini adalah untuk membantu pemaju untuk menulis kod dan melaksanakannya dalam projek mereka,,en,Berharap artikel ini akan menjadi tujuan yang,,en. Hope this article will serve that purpose.








Tagged on: ,
============================================= ============================================== Buy best TechAlpine Books on Amazon
============================================== ---------------------------------------------------------------- electrician ct chestnutelectric
error

Enjoy this blog? Please spread the word :)

Follow by Email
LinkedIn
LinkedIn
Share