How to configure Spring rely on Maven in

How to configure Spring rely on Maven in
How to configure Spring rely on Maven in

* Introduction:

This article discusses some of the details of how to configure Spring in Maven, introduced a good number of major Maven dependency management content, of course, there is something not discussed, but this article should be using Spring in the project here starting point. The latest Spring release can be found in the Maven repository. *

  1. On the basis of the configuration of Maven in Spring

Spring is highly modular and can be used alone Spring of a library without the need to rely on other libraries of Spring. For example, the library does not need to rely on the use of Spring Context Spring Persistence or Spring MVC library.

Let's start with the easiest start, spring-context-dependent configuration in Maven:

<properties>

<org.springframework.version>3.2.8.RELEASE</org.springframework.version>

<!-- <org.springframework.version>4.0.2.RELEASE</org.springframework.version> -->

</properties>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-context</artifactId>

<version>${org.springframework.version}</version>

<scope>runtime</scope>

</dependency>

Dependence on the spring-context defined embodiment, spring-context and injected into the vessel to achieve a dependence Spring: spring-core, spring-expression, spring-aop and spring-beans. These dependencies allow the container to support a number of core technologies Spring: Spring core components, Spring EL expression (SpEL), aspect-oriented programming, JavaBean mechanism.

Note that we define the scope of this dependency in runtime, so demand does not depend on the relevant Spring determine specific API during compilation. In some advanced scenarios, some of the Spring dependencies can not configure the runtime range, but in the current scenario projects relatively simple, do not need to compile the project for Spring to get the full functionality of the framework.

Also note that, starting from the Spring 3.2 need not be defined CGLIB dependent (current version is CGLIB 3.0). Now embedded in spring-core JAR (more detailed information can view the [JIRA] https://jira.springsource.org/browse/SPR-9669("JIRA ") in cglib package (net.sf.cglib now use org.springframework.cglib alternative ).

  1. In the Spring Maven configuration persistence framework

Now let's look at the configuration Spring persistence framework (mainly spring-orm)

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-orm</artifactId>

<version>${org.springframework.version}</version>

</dependency>

The above configuration increases Hibernate and JPA support functions, such as HibernateTemplate and JpaTemplate as well as some additional persistence-related dependencies: spring-jdbc and spring-tx

JDBC data access library defines Spring JDBC support and JdbcTemplate, Spring-tx provides a very flexible transaction management abstraction.

  1. Maven configuration in Spring MVC

To increase the Spring Web and Servlet support requires additional two dependencies in pom file above the configured:

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-web</artifactId>

<version>${org.springframework.version}</version>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-webmvc</artifactId>

<version>${org.springframework.version}</version>

</dependency>

spring-web package includes Servlet and Portlet common components needed, spring-webmvc MVC support is enabled in Servlet environment.

pom defined since the spring-web after spring-webmvc dependent on spring-web, so the definition of a spring-webmvc dependent, can not be displayed.

  1. Spring Security configuration in Maven

This section describes how to configure Spring Security relies in Maven, refer to this article.

  1. Configuration in Maven Spring Test

The following configuration can be dependent on the introduction Spring Test item

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-test</artifactId>

<version>${spring.version}</version>

<scope>test</scope>

</dependency>

Spring Test framework to start from Spring 3.2, Spring MVC Test project has been included into the core of the (originally a separate project, the project hosted on GitHub). Therefore, starting from Spring 3.2, spring-test configuration is only necessary to rely on the configuration-dependent.

Note: For Spring 3.1 and the following version of the application, a separate spring-mvc-test or dependence may be used, reference may be configured here. However, this is no longer rely on Maven central repository, so if you need to increase reliance need to configure a custom Maven container.

  1. Use Milestones (Milestones) version

The latest stable version is saved in the Spring Maven central repository, if the project requires the use of a milestone version of Spring, you need to configure the pom custom container:

<repositories>

<repository>

<id>repository.springframework.maven.milestone</id>

<name>Spring Framework Maven Milestone Repository</name>

<url>http://repo.spring.io/milestone/</url>;

</repository>

</repositories>

After the container was configured, like the following projects will be defined as dependent on the sample:

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-core</artifactId>

<version>3.2.0.RC2</version>

</dependency>

  1. Use Snapshots (Snapshots) version

Like the milestone version, version snapshot also need to configure a custom container Location:

<repositories>

<repository>

<id>repository.springframework.maven.snapshot</id>

<name>Spring Framework Maven Snapshot Repository</name>

<url>http://repo.spring.io/snapshot/</url>;

</repository>

</repositories>

When the position of the snapshot container configuration, the following configuration can be dependent on the use of:

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-core</artifactId>

<version>3.3.0.BUILD-SNAPSHOT</version>

</dependency>

For 4.x versions is the same:

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-core</artifactId>

<version>4.0.3.BUILD-SNAPSHOT</version>

</dependency>

**to sum up:

This is a summary of the main share of a how to configure Spring rely on Maven in the learning process, introduces some major Maven dependency management content, hoping to give us some inspiration, there is no right or need to fix the place Wang pointed out that chiefs

Like this article, you can point to the author likes to point at attention, will share Java-related articles every day!

Remember to focus on me oh, will occasionally presented benefits, including consolidation of interview questions, learning materials, source code, etc. ~~ **

Guess you like

Origin blog.51cto.com/14456091/2424275