Deploying the Spring project with Maven

Next, compile, package, and deploy the Spring MVC application using the Maven build tool. The Hibernate JPA API, the Hibernate Validator API, and the Hibernate Entity manager API are provided by WildFly 8.1. Add a dependency on the MySQL JDBC connector, as follows:

<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>5.1.22</version>
</dependency>

The Spring dependencies are available in the org.springframework group ID. The Spring version is configured as Spring 4.1.2 by default in pom.xml, as follows:

<version.spring>4.1.2.RELEASE</version.spring>

The Spring Web MVC dependency is also configured as version 4.1.2. All the required Spring framework dependencies—Spring AOP, Spring Beans, Spring Context, Spring Core, Spring JDBC, Spring ORM, Spring Tx, Log4j, AOP alliance, Commons logging, Cglib, Spring Expression Language, and Spring Web—are configured in pom.xml. In <build/>, configure the Maven compiler plugin and the Maven WAR plugin. Set the output directory for the Maven War plugin as the C:wildfly-8.1.0.Finalstandalonedeployments directory of the WildFly 8.1 standalone installation.

The pom.xml file is listed in the following code:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.jboss.springmvc</groupId>
  <artifactId>jboss-springmvc</artifactId>
  <packaging>war</packaging>
  <version>1.0.0</version>
  <name>Getting Started with Spring on JBoss</name>
  <properties>
    <!-- Spring version -->
    <version.spring>4.1.2.RELEASE</version.spring>
    <!-- Spring Third Party dependencies -->
    <version.aopalliance>1.0</version.aopalliance>
    <!-- Third Party dependencies -->
    <version.standard.taglibs>1.1.2</version.standard.taglibs>
    <version.commons.logging>1.1.1</version.commons.logging>
    <!-- JBoss AS plugin for deployment -->
    <version.jboss.as.maven.plugin>7.6.Final</version.jboss.as.maven.plugin>
  </properties>
  <repositories>
    <repository>
      <id>springsource-milestones</id>
      <name>SpringSource Milestones Proxy</name>
      <url>https://oss.sonatype.org/content/repositories/springsource-milestones</url>
    </repository>
    <repository>
      <id>Maven</id>
      <name>Maven</name>
      <url>http://repo1.maven.org/maven2</url>
    </repository>
  </repositories>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.jboss.spec</groupId>
        <artifactId>jboss-javaee-web-6.0</artifactId>
        <version>3.0.0.Final</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <!-- Spring dependencies -->
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${version.spring}</version>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${version.spring}</version>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${version.spring}</version>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>${version.spring}</version>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${version.spring}</version>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-expression</artifactId>
        <version>${version.spring}</version>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${version.spring}</version>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${version.spring}</version>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${version.spring}</version>
        <scope>test</scope>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${version.spring}</version>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${version.spring}</version>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${version.spring}</version>
      </dependency>
      <!-- Third Party dependencies -->
      <dependency>
        <groupId>aopalliance</groupId>
        <artifactId>aopalliance</artifactId>
        <version>${version.aopalliance}</version>
      </dependency>
      <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <version>${version.standard.taglibs}</version>
      </dependency>
      <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>${version.commons.logging}</version>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <!-- Import the JPA API using the provided scope It is included in JBoss AS 7 / EAP 6 -->
    <dependency>
      <groupId>org.hibernate.javax.persistence</groupId>
      <artifactId>hibernate-jpa-2.0-api</artifactId>
      <scope>provided</scope>
    </dependency>
    <!-- JSR-303 (Bean Validation) Implementation -->
    <!-- Provides portable constraints such as @Email -->
    <!-- Hibernate Validator is shipped in JBoss AS 7 -->
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-validator</artifactId>
      <version>4.1.0.Final</version>
      <exclusions>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <!-- Annotation processor that raising compilation errors whenever constraint annotations are incorrectly used. -->
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-validator-annotation-processor</artifactId>
      <version>4.1.0.Final</version>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-entitymanager</artifactId>
      <version>4.1.0.Final</version>
    </dependency>
    <!-- Import Spring dependencies, these are either from community or versions 	certified in WFK2 -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aop</artifactId>
      <version>${version.spring}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>${version.spring}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>${version.spring}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context-support</artifactId>
      <version>${version.spring}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>${version.spring}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-expression</artifactId>
      <version>${version.spring}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>${version.spring}</version>
      <!-- <scope>provided</scope> -->
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-orm</artifactId>
      <version>${version.spring}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-tx</artifactId>
      <version>${version.spring}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>${version.spring}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>${version.spring}</version>
    </dependency>
    <!-- Other community dependencies -->
    <dependency>
      <groupId>aopalliance</groupId>
      <artifactId>aopalliance</artifactId>
      <version>${version.aopalliance}</version>
    </dependency>
    <dependency>
      <groupId>taglibs</groupId>
      <artifactId>standard</artifactId>
      <version>${version.standard.taglibs}</version>
    </dependency>
    <dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
      <version>${version.commons.logging}</version>
    </dependency>
    <!-- Add cglib for the CatalogDaoTest -->
    <dependency>
      <groupId>cglib</groupId>
      <artifactId>cglib-nodep</artifactId>
      <version>2.2</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.22</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.5</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.0.1</version>
    </dependency>
    <!-- Add JSON dependency, specified in jboss-deployment-structure.xml -->
    <dependency>
      <groupId>org.codehaus.jackson</groupId>
      <artifactId>jackson-mapper-asl</artifactId>
      <version>1.9.3</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.codehaus.jackson</groupId>
      <artifactId>jackson-core-asl</artifactId>
      <version>1.9.3</version>
      <!-- <scope>provided</scope> -->
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
      <version>1.6.4</version>
      <!-- <scope>provided</scope> -->
    </dependency>
  </dependencies>
  <build>
    <finalName>jboss-springmvc</finalName>
    <plugins>
      <!-- Force Java 6 -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
      <!-- Deployent on AS from console -->
      <plugin>
        <groupId>org.jboss.as.plugins</groupId>
        <artifactId>jboss-as-maven-plugin</artifactId>
        <version>${version.jboss.as.maven.plugin}</version>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.2</version>
        <configuration>
          <outputDirectory>C:wildfly-8.1.0.Finalstandalonedeployments</outputDirectory>
          <failOnMissingWebXml>false</failOnMissingWebXml>
          <warName>${project.artifactId}</warName>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Some of the dependencies listed do not get used in the example application but could be used in some other Spring MVC application. Before we run the jboss-springmvc application, remove any test files and classes from the project. Also, remove import.sql from the resources directory.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset